Condition if on the elements of matrix in two For loop doesn't work
古いコメントを表示
Dear all, I posted my problem there is some days ago but I'didn't recieve a right answer. In my code, I use two for loops with some conditions on the elements of the matrix. thre is no error using two loops and the size of different parametrs and that of the matrix is right. But when I compare the rsults to that obtained using one for loop, I realised that the condition if doesn't work.
Any one has an idea!!!!
Thank you in advance. Adam
5 件のコメント
Azzi Abdelmalek
2012 年 8 月 21 日
why don't you post your code? how are we supposed to find out your problem?
Azzi Abdelmalek
2012 年 8 月 21 日
編集済み: Azzi Abdelmalek
2012 年 8 月 21 日
the value of xxb? give all your values
Jan
2012 年 8 月 21 日
Please, adam, omit the "clear all" because it is a frequently used, but always useless waste of time. If you are really convinced that a brute clearing helps you for any reasons, use "clear variables".
adam
2012 年 8 月 21 日
回答 (3 件)
Azzi Abdelmalek
2012 年 8 月 21 日
編集済み: Azzi Abdelmalek
2012 年 8 月 21 日
if i have understood whaat is your problem
- you are using if elseif elseif ....
- if the condition 1 is satisfied the other conditions will be skiped even they are true
- instead using if elseif elseif ... use
if exp1
%do
end
if exp2
%do
end
12 件のコメント
adam
2012 年 8 月 21 日
Azzi Abdelmalek
2012 年 8 月 21 日
編集済み: Azzi Abdelmalek
2012 年 8 月 21 日
ok it's a misunderstanding i tried your code, and it works, what is the problem? look at the updated answer
adam
2012 年 8 月 21 日
adam
2012 年 8 月 21 日
Azzi Abdelmalek
2012 年 8 月 21 日
編集済み: Azzi Abdelmalek
2012 年 8 月 21 日
Your if elseif elseif is not correct. i don't know exactly what are you looking for? but i can tell you that i found that your conditions are not exclusifs, which means if your condition 1 is true it claculate inter, then find the condtion 3 is true, then skip it that whhat you want?
adam
2012 年 8 月 21 日
adam
2012 年 8 月 21 日
adam
2012 年 8 月 21 日
Jan
2012 年 8 月 21 日
Whenever you mention in the forum, that an error appears, post the complete message and the line, which causes the error.
Azzi Abdelmalek
2012 年 8 月 21 日
please, writte the code with all data. what is a?
adam
2012 年 8 月 22 日
r=0:dr:5;
rr=r';
...
for l=1:length(xxb);
...
for m=1:length(rr)
if R<rr
Now rr is a vector, but R is a scalar. Then if R < rr is executed implicitly as
if all(R < rr) && ~isempty( R) && ~isempty(rr)
I guess you want something like if R < rr(m).
4 件のコメント
adam
2012 年 8 月 21 日
Jan
2012 年 8 月 21 日
You compare the results of two different codes, but you post one of them only. Of course we can only guess what the difference might be. "don't work" is a bad description of the problem. Do the results differ from your expectations (if so, how) or do you get an error message (if so, which one)? Did you use the debugger already to check the values of x and y? The debugger is more powerful and much more direct than asking the forum.
adam
2012 年 8 月 21 日
I repeat my suggestion to use the debugger by your own to find the cause of the differences. I still do not see a chance for us to distinguish correct from incorrect values, but you obviously have a method to do so.
And I recommend again to omit the useless but time consuming "clear all".
カテゴリ
ヘルプ センター および File Exchange で Lighting, Transparency, and Shading についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!