How does Matrix(300​2:2001:199​9998)=0.4 works?

조회 수: 1 (최근 30일)
WEI MA
WEI MA 2019년 4월 19일
댓글: James Tursa 2019년 4월 19일
I have a matrix with size of 1000*2000,
There is a line about : A(3002,2001,1999998) = 0.4 and the output looks like this
1.pngCan anyone help me to understand how this works?
Thanks in advance
  댓글 수: 1
James Tursa
James Tursa 2019년 4월 19일
I'm assuming this expression in your question is a typo
A(3002,2001,1999998)
and you really meant this based on your title
A(3002:2001:1999998)

댓글을 달려면 로그인하십시오.

답변 (3개)

madhan ravi
madhan ravi 2019년 4월 19일
Matrix = [1:3;4:6;7:9]
Matrix(1:2:end) = 0 % I suggest you to read about MATLAB indexing

Andrei Bobrov
Andrei Bobrov 2019년 4월 19일
[ii,jj] = ind2sub([1000,2000],3002:2001:1999998);
A = sparse(ii,jj,.4,1000,2000);

Walter Roberson
Walter Roberson 2019년 4월 19일
It is due to linear indexing. Variables can be indexed by a single number which is the number of elements from the beginning in continuous memory. Data is stored column by column (rows increase while column stays the same), so the first thing in memory is A(1,1), relative index 1, the second is A(2,1) relative index 2, then A(3,1) relative index 3, and so on, to A(1000,1) relative index 1000 . After that in memory is A(1,2), relative index 1001, then A(2,2) relative index 1002, A(3,2) relative index 1003, and so. 3000 would be the bottom of the third column, then 3001 would be the top of column #4, 3002 would be one entry down from that, at (4,2) .
Entries that are at the same row and adjacent columns are 1000 further on the location on the left (all in the case of 1000 rows that is). A difference of 2000 in memory would be same row, 2 columns earlier. 2001 further on from a location is therefore 2 columns to the right and 1 row down.. a chess move away. 2001 after that would be a further two columns to the right and another row down, and so on.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by