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 个评论
Image Analyst
2017-10-22
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.
回答(1 个)
Walter Roberson
2017-10-21
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 个评论
"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
2017-10-22
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
2017-10-22
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)
类别
在 帮助中心 和 File Exchange 中查找有关 Parallel Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!