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

2 visualizaciones (últimos 30 días)
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.

Respuestas (1)

David Hill
David Hill el 4 de Mzo. de 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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by