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 Kommentar

Image Analyst
Image Analyst am 22 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 21 Okt. 2017

1 Stimme

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 Kommentare

Cedric
Cedric am 22 Okt. 2017
Bearbeitet: Cedric am 22 Okt. 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 am 22 Okt. 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 am 22 Okt. 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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Parallel Computing finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 21 Okt. 2017

Kommentiert:

am 22 Okt. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by