using for loop to read multiple column vectors
Afficher commentaires plus anciens
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 commentaire
shah nawaz
le 12 Juin 2020
Réponses (1)
Matt J
le 12 Juin 2020
0 votes
11 commentaires
shah nawaz
le 14 Juin 2020
Matt J
le 14 Juin 2020
Why not as follows
fn=cell{5,1}
for i=1:5
fn{i}=import(___);
end
mean_fn=cellfun(@mean, fn)
shah nawaz
le 14 Juin 2020
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
le 14 Juin 2020
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
le 15 Juin 2020
shah nawaz
le 15 Juin 2020
shah nawaz
le 15 Juin 2020
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!