Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
How do I make this into a loop function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have several text files: (participant1, participant2, participant3,....participant5)
I have made these files using a loop. My loop for that is something like this:
for i = 1
empty_mat = zeros(0);
filename=['participant', subinfo_vect, '.txt']; %The subinfo_vect is a prompt that allows users to input %what number they are, so every time there is a new file.
dlmwrite(filename, [x,y,z,h], '-append'); %This appends the results x y z h within file
end
This code creates files corresponding to our prompt (subinfo_vect). Now I was wondering how to loop through these files (6 in total) so that we can catch the result and find the mean of those. To clarify the results, each file (txt) looks like this and I need to find the mean of column 2 and 3:
n =
1.0000 1.0000 1.2986 1.3973
1.0000 0 0.4159 0.5138
1.0000 1.0000 0.3955 0.4924
1.0000 0 0.3574 0.4539
1.0000 1.0000 0.3489 0.4458
1.0000 1.0000 0.4403 0.5372
How do I loop through 6 files that look like the above so that I can get the mean of all 6 in sequence? Any ideas?
What I have so far is a manual input of loading all the files. I am manually reading those files by adding:
dlmread('participant1.txt') <-- This however is manual, I want the computer to do it automatically without me giving the command, so something where I can just input a looping folder and it will read all the files one by one? Using a for loop?
Can you please help me with this
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!