- ‘B = max(dff_trans, [], 2);’ will create a column vector “B”, that contains the highest value from each row of the matrix dff_trans.
- ‘C = dff_trans(B > 2, :);’ will generate a new matrix “C”, that includes only the rows from the matrix “dff_trans” where the maximum value is greater than two.
- 'D = mean(C);’ will produce a row vector “D”, that contains the average values of each column in the matrix “C”.
Take each row in a matrix where the max number in that row is greater than 2, create new matrix. Average each column in the new matrix to result in one vector with average.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Caroline Szujewski
il 12 Ott 2023
Commentato: Caroline Szujewski
il 17 Ott 2023
I have a matrix dff_trans. I want to look through each row of the matrix and if the max value in that row greater than 2, I want to move that row to a new matrix. I then want to average each column in that new matrix to get a vector with the average at each time point (each column is a time point).
sum2z is the number of rows that have a max over 2 in the matrix dff_trans. length(dff_trans) is each time point.
c=1;
zscore_2 = zeros(sum2z,length(dff_trans));
if max(dff_trans(c,:))>2
zscore_2(c,:)=(dff_trans(c,:));
c=c+1;
end
0 Commenti
Risposta accettata
vidyesh
il 13 Ott 2023
Hi Caroline Szujewski,
I see that you want to generate a matrix with rows that have a maximum value greater than 2 and then calculate the average of each column in the new matrix.
You can achieve this using the below code:
B = max (dff_trans , [], 2);
C = dff_trans(B > 2, : );
D = mean(C);
You can also get your desired output with a single line of code:
D = mean( dff_trans (max( dff_trans , [], 2) > 2, : ))
Refer the following documentation to learn more about the 'max' function and how it can be used to operate on matrixes here:
Hope this answer helps.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!