Error on line 28 of a 9 line code?
Mostrar comentarios más antiguos
I have 365 text files of data, one for each day of the year. I have this code to create 12 new text files, monthly averages.
clear all
S = dir('*.txt');
N = {S.name};
for k = 1:numel(S)
A = load(N{k});
final = mean (N);
[~,name] = fileparts(N{k});
dlmwrite(sprintf('%s.txt',name),final)
end
I get the Error
Undefined function 'sum' for input arguments of type 'cell'.
Error in mean (line 28)
y = sum(x)/size(x,dim);
Error in Refining_to_Monthly (line 6)
final = mean (N);
I don't understand the error in general, but especially don't understand how there can be an error on line 28 of the code, when it is not even 28 lines long. Any help greatly appreciated.
Thank you in advance
Respuesta aceptada
Más respuestas (1)
Gurudatha Pai
el 7 de Sept. de 2015
The error is on line 28 of the function mean.
mean()
The function mean cannot work on cell arrays. You would want to call
mean(cell2mat(N))
or something like that.
1 comentario
Walter Roberson
el 7 de Sept. de 2015
Probably
final = mean(A);
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!