Azzera filtri
Azzera filtri

Can I run for loop in command window?

6 visualizzazioni (ultimi 30 giorni)
bkshn
bkshn il 4 Dic 2014
Modificato: Matt J il 4 Dic 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

Risposta accettata

Matt J
Matt J il 4 Dic 2014
Modificato: Matt J il 4 Dic 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.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by