How to save output from loops into matrix w/o using vector input?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Allen Chang
le 5 Déc 2019
Commenté : Allen Chang
le 5 Déc 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 commentaires
Réponse acceptée
JESUS DAVID ARIZA ROYETH
le 5 Déc 2019
Modifié(e) : JESUS DAVID ARIZA ROYETH
le 5 Déc 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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!