• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Matlab question about indices of arrays being vectors.

cirthix

Diamond Member

>> fake_matrix=ones(5), fake_vector=ones(2,1), fake_matrix(fake_vector), fake_matrix(fake_vector(1), fake_vector(2))

fake_matrix =

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1


fake_vector =

1
1


ans =

1
1


ans =

1

Why does one give a scalar result and the other a vector?
 
The second gives you a scalar because you are asking for the value stored at a certain location of a matrix think: matrix(y, x) like a coordinate.

The first gives you the a "vector" because you are asking for multiple components. In this case you are asking for the 1st element in the matrix 2 times (if you treat the matrix as a list rather than as a matrix.

In the future, its helpful to not use a uniform matrix when looking at these questions.
 
Back
Top