Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
dpb
dpb el 17 de Mzo. de 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]

Iniciar sesión para comentar.

Respuesta aceptada

Marta Salas
Marta Salas el 17 de Mzo. de 2014
Editada: Marta Salas el 17 de Mzo. de 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 comentario
Rod
Rod el 2 de Abr. de 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 ;)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by