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

3 ビュー (過去 30 日間)
Evan Bakalars
Evan Bakalars 2021 年 3 月 4 日
回答済み: David Hill 2021 年 3 月 4 日
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 Center および File ExchangeGeometric Geodesy についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by