Borrar filtros
Borrar filtros

Writing loops for vectors?

1 visualización (últimos 30 días)
Nick Haufler
Nick Haufler el 2 de Oct. de 2015
Respondida: Andrei Bobrov el 2 de Oct. de 2015
In the attached document how do you write a loop to switch the numbers in a vector. It has to be done in the same way table a was done. If the 1st value is larger than the 2nd then switch them. Then do 2 and 3....etc.

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 2 de Oct. de 2015
it is homework
x = [1 -2 3 5 4 2];
x1=x;
for ii = 1:5, if x1(ii) > x1(ii+1), x1(ii:ii+1) = x1([ii+1,ii]); end; end

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