How to save output from loops into matrix w/o using vector input?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Allen Chang
il 5 Dic 2019
Commentato: Allen Chang
il 5 Dic 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 Commenti
Risposta accettata
JESUS DAVID ARIZA ROYETH
il 5 Dic 2019
Modificato: JESUS DAVID ARIZA ROYETH
il 5 Dic 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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!