How to save output from loops into matrix w/o using vector input?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Allen Chang
el 5 de Dic. de 2019
Comentada: Allen Chang
el 5 de Dic. de 2019
Hi,
I am running a loop in order to run the same code and to extract the sum in each matlab file.
I am able to get the sum for each iteration but I am having trouble saving it in a matrix/array. Each answer I have seen online uses the input vector variable to create the matrix but I am not using vectors as the input.
So ideally I would like a matrix with the name of the file in the first column and the extract sum in the second column.
Any help, especially basic videos that might help me understand the process better would be super helpful.
Thank you in advance...code below...
%% Load Matlab Directory
myFolder = pwd; % Wherever you want.
filePattern = fullfile(myFolder, '*.mat*')
theFiles = dir(filePattern)
allFileNames = {theFiles.name};
%% Dki mean and obtains sum
for ii=allFileNames(1,:)
a=load(ii{1});
b=a.md_dki_jhu;
dki=b.mean;
d=dki([11,15,23,25,29,71,79,81,182,13,31,37,39,41,43,51,184,186]);
sum=sum(d)
end
0 comentarios
Respuesta aceptada
JESUS DAVID ARIZA ROYETH
el 5 de Dic. de 2019
Editada: JESUS DAVID ARIZA ROYETH
el 5 de Dic. de 2019
test it
%% Load Matlab Directory
myFolder = pwd; % Wherever you want.
filePattern = fullfile(myFolder, '*.mat*')
theFiles = dir(filePattern)
allFileNames = {theFiles.name};
%% Dki mean and obtains sum
data=repmat({[]},length(allFileNames),2);
for ii=1:numel(allFileNames)
a=load(allFileNames{ii});
b=a.md_dki_jhu;
dki=b.mean;
d=dki([11,15,23,25,29,71,79,81,182,13,31,37,39,41,43,51,184,186]);
getsum=sum(d)
data{ii,1}=allFileNames{ii};
data{ii,2}=getsum;
end
disp(data)
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!