Two part question: Labeling a row in a matrix and finding certain values
1 view (last 30 days)
Show older comments
This is a two part question
Part 1: If I have this matrix -> DraftMatrix = [1:20;randi([50,90],1,20);randi([0,8],1,20)];
How can I assign two different variables to the second and third row of the matrix without making three vectors and combining them into a matrix?
Part 2: If I have the same matrix -> DraftMatrix = [1:20;randi([50,90],1,20);randi([0,8],1,20)];
How would I go about finding the max value in the second row and labeling it in a new column array with all three values: the first row value, second row value (the one I am finding the max for), and the third row values?
Any help is much appreciated, thank you very much.
0 Comments
Answers (1)
David Hill
on 4 Mar 2021
Normally, you should not establish new variables but just index.
DraftMatrix = [1:20;randi([50,90],1,20);randi([0,8],1,20)];
a=DraftMatrix(2,:);%assigning variable a to second row
b=DraftMatrix(3,:);%assigning variable b to third row
c=max(DraftMatrix,[],2);%provides column vector with max value of each row
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!