Two part question: Labeling a row in a matrix and finding certain values

1 Ansicht (letzte 30 Tage)
Evan Bakalars
Evan Bakalars am 4 Mär. 2021
Beantwortet: David Hill am 4 Mär. 2021
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.

Antworten (1)

David Hill
David Hill am 4 Mär. 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

Community Treasure Hunt

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

Start Hunting!

Translated by