how to give range of values to variable

12 visualizaciones (últimos 30 días)
praveena maddamsetty
praveena maddamsetty el 25 de Feb. de 2016
Comentada: Walter Roberson el 25 de Feb. de 2016
please tell me how to code below statments.
for i from 0 to 255
s[i]:=i

Respuestas (2)

Stephen23
Stephen23 el 25 de Feb. de 2016
Editada: Stephen23 el 25 de Feb. de 2016
Why use slow and ugly loops? This is MATLAB!
s = 0:255;
Note that MATLAB uses one-based indexing, so s(0) is an error.

Walter Roberson
Walter Roberson el 25 de Feb. de 2016
for i = 0 : 255
s(i+1) = i;
end
Or
s = 0 : 255; %no loop needed
  2 comentarios
praveena maddamsetty
praveena maddamsetty el 25 de Feb. de 2016
thanks a lot. i am new to matlab if possible please tell how to swap two matrises. deal is not working for swaping s(i) and s(j)
Walter Roberson
Walter Roberson el 25 de Feb. de 2016
s([i j]) = s([j i])

Iniciar sesión para comentar.

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