Load files inside a while loop
Show older comments
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 Comment
Image Analyst
on 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.
Answers (1)
Walter Roberson
on 21 Oct 2017
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 Comments
"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
on 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
on 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)
Categories
Find more on Parallel Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!