How do we write double matrix as an expression?

2 visualizaciones (últimos 30 días)
NN
NN el 8 de Feb. de 2023
Respondida: Jasvin el 9 de Feb. de 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 comentario
Les Beckham
Les Beckham el 8 de Feb. de 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

Iniciar sesión para comentar.

Respuestas (1)

Jasvin
Jasvin el 9 de Feb. de 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.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by