Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do I make this into a loop function?

1 回表示 (過去 30 日間)
Tab for Lab
Tab for Lab 2015 年 11 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Guillaume
Guillaume 2015 年 11 月 10 日
See this Answer in the FAQ on processing a sequence of files.
  2 件のコメント
Tab for Lab
Tab for Lab 2015 年 11 月 10 日
I understand that we can get the sequence like this, My question is something different. I already made my 6 files through a sequence.
Guillaume
Guillaume 2015 年 11 月 10 日
The FAQ gives you several ways of reading a sequence of files. Isn't it what you're after?
"How do I loop through 6 files" is exactly what the FAQ answer.

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by