How do we write double matrix as an expression?

2 views (last 30 days)
NN
NN on 8 Feb 2023
Answered: Jasvin on 9 Feb 2023
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 Comment
Les Beckham
Les Beckham on 8 Feb 2023
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

Sign in to comment.

Answers (1)

Jasvin
Jasvin on 9 Feb 2023
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.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!