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