How to interpret matrix indexation? Help to translate specific case please.

1 次查看(过去 30 天)
Hi;
I am new using MATLAB, I regularly make programs in C++ and I am trying to translate the following piece of code into C++. I understand how repmat works and some of the indexations of matrices but I have been searching and I really have not found nor understood how does the last line works. I understand I am assigning "something" to F1, what I specifically do not understand is the part between brackets []. I reckon the colon is to "copy" the entire column and the number 1 in the ends refers that the F1 is the one I am getting the info. I my assumptions are correct please let me know.
I appreciate your time and your help to explain me. Thank you!
MATLAB code
nx=3; ny=3;
F=repmat(0.11,[nx ny 2]);
F(:,:,1)=F([nx 1:nx-1],:,1)
  1 个评论
dpb
dpb 2014-3-17
Why don't you just look at it in the command window? Using some data other than a constant so you can see specifically who came from where would make it easier.
[nx 1:nx=1]
is a vector--in you specific case it's easily enough seen by simply plugging in values to be
[3 1:3-2] --> [3 1:2] --> [3 1 2]

请先登录,再进行评论。

采纳的回答

Marta Salas
Marta Salas 2014-3-17
编辑:Marta Salas 2014-3-17
You create a a 3dimesional matrix with the repmat: 3x3x2
The last line of code takes the matrix assigned on 3rd dimesion= 1 and reorders the rows. The code in brackets is the new order ([3 1 2] in your example)
  1 个评论
Rod
Rod 2014-4-2
Thanks a lot Marta, I did not know it re-orders rows (or even columns) since I had a constant value in the matrix and it is not obvious visually. Now I understand ;)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by