What does [ ]; do in MATLAB?

139 visualizaciones (últimos 30 días)
JK
JK el 19 de Oct. de 2014
Respondida: the cyclist el 19 de Oct. de 2014
Hi, I am looking at some codes. It solves for c at the end,
but it defines c=[]; in the beginning which is like empty matrix.
So what does it do ?

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Oct. de 2014
Usually I see that in cases where it must be something because in a loop you're concatenating something onto c. And if c is not defined yet you'll get an error, but it it's something, anything, even null, it's okay. Something like
c = [];
for k = 1 : 5
c = [c, k];
end
If we didn't define c as null then the c= line inside the for loop would throw an exception the very first time.

Más respuestas (1)

the cyclist
the cyclist el 19 de Oct. de 2014

Categorías

Más información sobre Loops and Conditional Statements 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