Perform mathematical operation on matching values
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
ea
il 5 Gen 2017
Modificato: Mohammad Abouali
il 5 Gen 2017
I know how to extract the value of column 3 when column 2 matches a specified integer (in this case 21).
A(A(:,2)==21,3;
How do I alter this expression to not only extract the value of column 3 (when column 2 equals 21) but also perform a mathematical operation on the extracted value.
For example, I'd like to extract the value from column 3 and subtract it from 186.
Any suggestions?
0 Commenti
Risposta accettata
Mohammad Abouali
il 5 Gen 2017
Modificato: Mohammad Abouali
il 5 Gen 2017
One way is this:
mask = (A(:,2)==21);
% performing the operation and storing it back in A:
% mask is used twice, so I compute it once and use it two times.
A(mask,3) = 186 - A(mask,3);
% Performing the operation but storing it in a separate variable:
% Here since mask is used once you don't need to store it in a separate variable.
newVariable = 186 - A(mask,3);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Author Block Masks 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!