Code only works in the command window
Mostrar comentarios más antiguos
Hi MATLAB community,
I am trying to execute the follow code, but this only works in the command window and not editor.
Could you help me?
Guilherme Lopes de Campos
% dados is a matriz 13817 rows and 3 columns
function [matriz_medias] = gerar_medias(dados)
[linha,coluna]=size(dados);
matriz(1:linha,1:4)=zeros;
matriz(1:linha,2:4)=dados;
j=1;
k=1;
ano_ini=matriz(1,3);
for i=k:linha
if matriz(k,3)==ano_ini
matriz(k,1)=j;
k=k+1;
while matriz(k,3)==ano_ini
matriz(k,1)=j;
k=k+1;
end
while matriz(k,3)>ano_ini
matriz(k,1)=j;
k=k+1;
end
end
j=j+1;
end
matriz_media=zeros(((matriz(linha,3)-matriz(1,3))+1)*12,(matriz(linha,1)+2));
instrumento=1;
ano=matriz(1,3);
mes=1;
for i=1:((matriz(linha,3)-matriz(1,3))+1)*12
if rem(i,12)~=0
matriz_media(i,1)=ano;
matriz_media(i,2)=mes;
mes=mes+1;
else
matriz_media(i,1)=ano;
matriz_media(i,2)=mes;
mes=1;
ano=ano+1;
end
end
mes=1;
n=0;
j=1;
soma=0;
instrumento=1;
diferenca=0;
for i=1:linha
if matriz(i,2)==mes
soma=soma+matriz(i,4);
n=n+1;
else
matriz_media(j,instrumento+2)=soma/n;
soma=0;
n=0;
diferenca=matriz(i,2)-mes;
if diferenca>1
for k=1:(diferenca-1)
j=j+1;
matriz_media(j,instrumento+2)=999999;
mes=mes+1;
end
diferenca=0;
end
soma=matriz(i,4);
n=1;
if mes<12
mes=mes+1;
else
mes=1;
end
if matriz(i,1)~=instrumento
instrumento=instrumento+1;
j=j+1;
end
end
end
end
2 comentarios
OCDER
el 8 de Feb. de 2019
How are you executing your code in the command window and what do you mean it runs in the editor? Are you getting an error message? If so, copy paste the full error message.
Guilherme Lopes de Campos
el 8 de Feb. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!