How to interpret matrix indexation? Help to translate specific case please.
1 view (last 30 days)
Show older comments
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 Comment
dpb
on 17 Mar 2014
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]
Accepted Answer
Marta Salas
on 17 Mar 2014
Edited: Marta Salas
on 17 Mar 2014
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)
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!