Filter löschen
Filter löschen

Can I run for loop in command window?

6 Ansichten (letzte 30 Tage)
bkshn
bkshn am 4 Dez. 2014
Bearbeitet: Matt J am 4 Dez. 2014
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

Akzeptierte Antwort

Matt J
Matt J am 4 Dez. 2014
Bearbeitet: Matt J am 4 Dez. 2014
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by