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

2 次查看(过去 30 天)
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