So, I have created a matrix called cent in another for loop, and then:
for
... creates "cent"
end
e = 5 ;
per = zeros(e,e)
for u = 1:e
rsum = 0;
a = 0;
for p=1:e
u
p
Xdiff = 0;
Ydiff = 0;
Zdiff = 0;
Xdiff = (cent(u,1)-cent(:,1)).^2
Ydiff = (cent(u,2)-cent(:,2)).^2
Zdiff = (cent(u,3)-cent(:,3)).^2
a = (Xdiff + Ydiff + Zdiff).^0.5
rsum = cent(u,6) + cent(:,6) ;
if a == rsum(p)
per(p,u) = p ;
else
per(p,u) = 0 ;
end
end
end
The script runs just fine, and I get no error messages. However, i get no display of u and p, and per is returned as a matrix with only zeros if i create it before the first for loop. If i create per as shown below, between the two loops, it is not created at all. I thus think that the code never enters the second loop and run it. Why?

回答 (1 件)

Thorsten
Thorsten 2016 年 8 月 17 日

0 投票

I have created some sample values for cent and the program runs just fine, entering the second loop as expected. The reason that per is all zero is that the condition
a == rsum(p)
is never true.

4 件のコメント

Jonathan Oekland Torstensen
Jonathan Oekland Torstensen 2016 年 8 月 17 日
Are you sure? Because it never displays p or u in the promt, which it should if it runs the loop.
Jonathan Oekland Torstensen
Jonathan Oekland Torstensen 2016 年 8 月 17 日
Im pretty sur it doesnt run, because I get that per is undefined after running the code.
Jonathan Oekland Torstensen
Jonathan Oekland Torstensen 2016 年 8 月 17 日
Any other suggestions?
Image Analyst
Image Analyst 2016 年 8 月 17 日
Use the debugger to step through the code line by line and examine variables and see where it goes. That's what everyone does.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

タグ

コメント済み:

2016 年 8 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by