using for loop to read multiple column vectors
이전 댓글 표시
I want to use a for loop to read different column vectors which are mentioned with different fn data in attached file and then I want to plot several figures from the output of for loop. Main problem is I don't know how to import fn vector data multiple times in loop and replace it with next fn vector when code complete for previous loop.
I have already imported data from txt file by using import tool and named the columns with variable names. fn is a varible which has name fn 10, fn22, fn32.... these are 5 column vectors.
답변 (1개)
Matt J
2020년 6월 12일
0 개 추천
댓글 수: 11
shah nawaz
2020년 6월 14일
Matt J
2020년 6월 14일
Why not as follows
fn=cell{5,1}
for i=1:5
fn{i}=import(___);
end
mean_fn=cellfun(@mean, fn)
shah nawaz
2020년 6월 14일
You can do things like,
fn = {file199 file171 file132 file122 file110 };
mfn=cellfun( @(c)mean(c(:,3)), fn);
You could also take the means of all columns like so,
fn = {file199 file171 file132 file122 file110 };
mfn=cellfun( @(c)mean(c), fn, 'uni',0);
shah nawaz
2020년 6월 14일
That should not matter. For example,
>> fn={rand(4,3), rand(10,3)}
fn =
1×2 cell array
{4×3 double} {10×3 double}
>> mfn=cellfun( @(c)mean(c), fn, 'uni',0)
mfn =
1×2 cell array
{1×3 double} {1×3 double}
or
>> mfncol3=cellfun( @(c)mean(c(:,3)), fn)
mfncol3 =
0.5084 0.6062
shah nawaz
2020년 6월 15일
shah nawaz
2020년 6월 15일
shah nawaz
2020년 6월 15일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!