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!