Can I run for loop in command window?

조회 수: 7 (최근 30일)
bkshn
bkshn 2014년 12월 4일
편집: Matt J 2014년 12월 4일
Hello
I have for loop with switch case in code , my code is here.
if true
for i=3:2:length(vx)
switch vx(i+1)-vx(i-1)
case -2
vx(i)=vx(i-1)-1
case -1
rowIdx=[i,i];
colIdx=[vx(i-1),(vx(i-1)-1)];
mat3Elements=X(sub2ind(size(X),rowIdx,colIdx));
[minValue,minIdx]=min(mat3Elements);
vx(i)=colIdx(minIdx);
case 0
rowIdx=[i,i,i];
colIdx=[vx(i-1),(vx(i-1)-1),(vx(i+1)+1)];
mat3Elements=X(sub2ind(size(X),rowIdx,colIdx));
[minValue,minIdx]=min(mat3Elements);
vx(i)=colIdx(minIdx);
case 1
rowIdx=[i,i];
colIdx=[vx(i-1),(vx(i-1)+1)];
mat3Elements=X(sub2ind(size(X),rowIdx,colIdx));
[minValue,minIdx]=min(mat3Elements);
vx(i)=colIdx(minIdx);
case 2
vx(i)= vx(i-1)+1; end end end
How can I run it in command window? when I paste whole of code in command window it didn't work.
Could you help me?
thamks

채택된 답변

Matt J
Matt J 2014년 12월 4일
편집: Matt J 2014년 12월 4일
when I paste whole of code in command window it didn't work.
It should have worked. Another option is to highlight the portion of code you want executed and press F9 (or righ-click and select "Evaluate Selection"). It will then execute at the command line.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by