Load files inside a while loop

Is it possible to load files inside a while loop? I'm not able to load it before the loop, and it also doesn't load inside of it.

1 commentaire

Image Analyst
Image Analyst le 22 Oct 2017
What do you mean by "it"? Just how many files are there? One or more? What did you observe? A permission error? A "file not found" error? Attach your code and any and all red error text.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 21 Oct 2017

1 vote

Yes.
while SomeCondition
some code
end
is the same as
for hidden_internal_variable = 1 : inf
if ~SomeCondition
break;
end
some code
end
except that in the case of 1 : inf, MATLAB will stop after at most 9223372036854775806 iterations (which is 2^63) whereas the while loop could go on until interrupted.
This equivalence of while and for loops is of theoretical importance because it is known that files can be loaded in a for loop. http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

3 commentaires

Cedric
Cedric le 22 Oct 2017
Modifié(e) : Cedric le 22 Oct 2017
"This equivalence of while and for loops is of theoretical importance because it is known that files can be loaded in a for loop. +ref. FAQ"
That made me laugh on a Saturday night while stuck behind my computer trying to move forward with my paper. Nice perf.! ;-)
Walter Roberson
Walter Roberson le 22 Oct 2017
A mathematician and a physicist were asked the following question:
Suppose you walked by a burning house and saw a hydrant and a hose not connected to the hydrant. What would you do?
P: I would attach the hose to the hydrant, turn on the water, and put out the fire.
M: I would attach the hose to the hydrant, turn on the water, and put out the fire.
Then they were asked this question:
Suppose you walked by a house and saw a hose connected to a hydrant. What would you do?
P: I would keep walking, as there is no problem to solve.
M: I would disconnect the hose from the hydrant and set the house on fire, reducing the problem to a previously solved form.
Cedric
Cedric le 22 Oct 2017
Thanks, I had a French variant of this joke but the English version is better! (as French mathematicians could apparently negotiate that the house was already on fire in the second case)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Parallel Computing dans Centre d'aide et File Exchange

Commenté :

le 22 Oct 2017

Community Treasure Hunt

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

Start Hunting!

Translated by