for-next loop parameter gets printed out
2 ビュー (過去 30 日間)
古いコメントを表示
Curious behavior. I have a matlab code with lots of for-next loops. One in particular that starts with
for I = J:LL
for some reason resulted in the LL value being printed out unexpectedly. None of my other for-next loops
did this. When I changed the statement to read
for I = J:LL;
i.e., I added a semicolorn to the end, LL was NOT printed out. This is worrisome because I'm not sure something
else has gone wrong. How does one track down what causes this behavior?
2 件のコメント
dpb
2022 年 8 月 20 日
Can you post a code snippet that exhibits the suspect behavior?
I've never seen it happen but I've not upgraded to a more recent release than R2020b yet, either, if somehow something got broken in an update.
採用された回答
dpb
2022 年 8 月 21 日
編集済み: dpb
2022 年 8 月 21 日
You've got a malformed for expression, the comma serves to make a second line of code on the same source line; the value of ll is echo'ed to the screen as asked for by this syntax.
for l = 1,ll
...
end
is syntactically the same as
for l = 1
ll
...
end
You undoubtedly intended to write
for l=1:ll
...
end
So, indeed, something else did go wrong besides; the loop only executed once instead of ll times since were no colon operators to set either step nor upper bound.
And, in this case the typo is also not a syntax error nor can the parser presume you didn't have some reason for only executing the loop once.
6 件のコメント
dpb
2022 年 8 月 22 日
Your test code before ran here with the correction noted; I don't know what answers should be, of course, but it ran to completion with the fix for the loop construct alone. There are a couple of warnings on suggested better syntax, but none that are of computational significance.
As for the conversion, I've not looked at the code much at all, but unless there were a huge amount of it and/or I didn't really know what it was trying to do, my first inclination would be to not do 1:1 translation but rewrite a MATLAB solution using MATLAB syntax and idioms instead of Fortran's.
The unfortunate decision by TMW to not support anything except Intel for mex is a real kick in the private parts that is, frankly, :just plain rude!" to long-term users but there seems to be no leverage to be able to use to get them to change course. Supporting the fortran compiler with gcc would be a major help and seems like should be essentially trivial to add to the existing support, or to simply just open up the interface and document the libraries and linking to let use any compiler. I fail to grasp the logic behind their current position. Anyways, as of now it appears that using Intel compiler is the only practical choice for going the mex route and they (Intel) have now also closed off that option except for "the high-priced spread" route.
It's an impasse, indeed...
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!