Need clarity of this command

1 visualización (últimos 30 días)
moonman
moonman el 8 de Oct. de 2011
I am having these commands
a = [697 770 852 941];
b = [1209 1336 1477];
%them later in code
f = [];
for c=1:4,
for r=1:3,
f = [ f [a(c);b(r)] ]; % WHAT IS function of this command
end
end
Plz explain this command
f = [ f [a(c);b(r)] ];
and what does this do
f = []; %does it make empty matrix

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 8 de Oct. de 2011
You are right.
f=[]; % make f an empty matrix
a=1;b=2;
f=[a;b] % doing vertical concatenation
f=[a b] % doing horizontal concatenation
doing f=[f [a(c);b(r)] ] in a loop is expanding f. It's not a good programming technique though.

Más respuestas (1)

moonman
moonman el 8 de Oct. de 2011
So kindly tell me the good way to do this as i am also confused abt this statement of book
f = [ f [a(c);b(r)] ]; why f is written in the bracket
  1 comentario
Fangjun Jiang
Fangjun Jiang el 8 de Oct. de 2011
Start f as [], just run the following one at a time to test it out.
f=[f [1;2]]
f=[f [3;4]]
f=[f [400;500]]

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by