How do we write double matrix as an expression?

조회 수: 1 (최근 30일)
NN
NN 2023년 2월 8일
답변: Jasvin 2023년 2월 9일
In matlab how do we write 1441x2 double matrix as an expression to specify any particular element , say 2x2
it is saved as Cost in the workspace.
  댓글 수: 1
Les Beckham
Les Beckham 2023년 2월 8일
Are you asking how to pick out a certain section of the matrix to operate on?
Please explain what you mean by "write as an expression".
You should read this documentation page: Array Indexing
Also, I would recommend taking the time to go through the online tutorial here: Matlab Onramp

댓글을 달려면 로그인하십시오.

답변 (1개)

Jasvin
Jasvin 2023년 2월 9일
Assuming that you want to extract a 2x2 sub-matrix from a 1441x2 double matrix called "cost", here is how you would do that considering you want the 1st and 2nd columns from the 15th and 16th rows of the cost matrix,
cost(15:16, :)
This indexing means that you want all the rows from 15th to 16th and all the columns in the matrix which in this case would be the 1st and 2nd columns.
If you want two disjoint rows to be selected then you can do that too,
cost([16 1], :)
Note that this would fetch the rows in the same order that you specify in the indexing, so in this case the 16th row would be followed by the 1st row.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by