can anyone please explain X0(1:2) where X0=[0,0,0]' , i wrote X0(2:2) and gave answer 0 i tht it shoudl give error . what i understand is X0(1:2) is 1 row 2 element. please correct me
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
can anyone please explain X0(1:2) where X0=[0,0,0]' , i wrote X0(2:2) and gave answer 0 i tht it shoudl give error . what i understand is X0(1:2) is 1 row 2 element. please correct me
also i made a small 2x2 matrix P and
p =
2 3
4 5
>> p(1:2)
ans =
2 4
>> p(2:2)
ans =
4
0 comentarios
Respuestas (2)
dpb
el 4 de Nov. de 2020
Linear addressing. Arrays are stored in column-major order.
See https://www.mathworks.com/help/matlab/math/array-indexing.html for discussion of various addressing modes/syntax.
0 comentarios
Steven Lord
el 4 de Nov. de 2020
v = 2:2 is the vector formed by starting at 2 and going to 2 by steps of 1. That vector is equivalent to writing v = [2] or v = 2.
The expression A(v) where v is a numeric vector performs linear indexing. See the "Indexing with a Single Index" section on this documentation page or this blog post for more infomation on linear indexing.
v = 1:10;
x = v.^2;
y = x([4 5]) % Elements 4 and 5 of x. From the way we created x this is [16, 25]
If you had an array and wanted to get the element in the fourth row, fifth column using 4 and 5 that would be subscripted indexing. That documentation page to which I linked above has a section ("Indexing with Element Positions") on subscripted indexing as well.
M = magic(6)
z = M(4, 5)
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!