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

1 次查看(过去 30 天)
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.

回答(1 个)

David Hill
David Hill 2021-3-4
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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by