# matrix loop how to extract data

2 Ansichten (letzte 30 Tage)
cormac spillane am 27 Apr. 2015
Hello, I have created a loop in a matrix and would just like to extract data but am not sure how? for example i would like to extract each set of means from column 2 for each of these samples within the loop P1R = mean(P1);
P2R = mean(P2);
P3R = mean(P3);
P4R = mean(P4);
P5R = mean(P5);
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Michael Haderlein am 27 Apr. 2015
What do you mean with "extract data"? You mean, instead of writing those 5 lines P1R=mean(P1); and so on, you want to do in a loop? If so, all you have to do is to change P1, P2 and so on to one array P. If all the Px have been column arrays before, then P(:,1) should then correspond to P1 and so on. If they have been row arrays, P(1,:) should be the respective sub array. Depending on this, you get all the mean values with mean(P, dim) with dim being the dimension along the averaging should take place (1 means mean of each column, 2 means mean of each row).
Although it might look attractive at first sight, please don't use eval here. Just saying.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by