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.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 10월 2일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2015년 10월 2일

답변:

2015년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by