Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Rod
Rod le 17 Mar 2014
Commenté : Rod le 2 Avr 2014
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 commentaire
dpb
dpb le 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]

Connectez-vous pour commenter.

Réponse acceptée

Marta Salas
Marta Salas le 17 Mar 2014
Modifié(e) : Marta Salas le 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)
  1 commentaire
Rod
Rod le 2 Avr 2014
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 ;)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by