How to make a new column in my table
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have the following in my table (Results) of 550 rows:
A = audsActual %in the second row
P = audsPreds %in the third row
I want to make a 4th column that checks if for each row, if A = P, then it says 1. if not, it says 0.
I wrote this code but it is not working:
if Results(2,:) == Results(3,:)
Results (4,:) = 1
elseif Results (4,:) = 0
It's giving me an error message. Please help, thank you!
0 commentaires
Réponses (1)
Walter Roberson
le 25 Jan 2023
elseif requires a expression after it, but you coded an assignment.
You just want else not elseif
Remember that
if Results(2,:) == Results(3,:)
is going to test all of row 2 against all of row 3, creating a logical vector of true and false. if and while consider a test to be true only if all of the values being tested are non-zero, so the code you wrote is equivalent to
if all(Results(2,:) == Results(3,:))
which is not what you want.
What you really need to do is read about logical indexing. https://blogs.mathworks.com/loren/2013/02/20/logical-indexing-multiple-conditions/
1 commentaire
Walter Roberson
le 25 Jan 2023
Though in this particular case you could just code
Results(4,:) = Results(2,:) == Results(3,:);
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!