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
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
dpb
2020년 11월 4일
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
Steven Lord
2020년 11월 4일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!