inverse loop

366 vues (au cours des 30 derniers jours)
Arundhatee Talukdar
Arundhatee Talukdar le 22 Nov 2011
I want to use loop from i=180:1 and again next inserted loop j=180:1 Does matlab allow that? how I access (180,180) first rather then (0,0)...
  1 commentaire
Amr
Amr le 12 Oct 2016
sure ... use this command for i=180:-1:1 for j=180:-1:1

Connectez-vous pour commenter.

Réponses (3)

Fangjun Jiang
Fangjun Jiang le 22 Nov 2011
for i=180:-1:1
for j=180:-1:1
  1 commentaire
Scott
Scott le 14 Sep 2022
thanks

Connectez-vous pour commenter.


Jan
Jan le 22 Nov 2011
Modifié(e) : Walter Roberson le 1 Sep 2024
Whenever you have a problem with a specific command, be sure to read the help and doc text for this command:
help for
Step S with increments of -0.1
for S = 1.0: -0.1: 0.0, do_some_task(S), end

Thomas
Thomas le 22 Nov 2011
Try,
for i=180:-1:1
for j =180:-1:1
i
j
end
end
  5 commentaires
Walter Roberson
Walter Roberson le 1 Sep 2024
The question @MH asked is about automatically inverting the order of two loops, without having to have a switch() statement. In one case in their example the loops are nested j within i, and in the other case the loops are nested i within j.
The answer to the question is "No, there is no dialog box or editor option to automatically reverse the nesting order. You would need something like
for outer = start:step:fin
for inner = start:step:fin
if ReverseLoop
i = outer; j = inner;
else
i = inner; j = outer;
end
%code
end
end
MH
MH le 1 Sep 2024

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by