Why is this if statement not working?

조회 수: 1 (최근 30일)
Jay
Jay 2016년 10월 24일
댓글: Jay 2016년 10월 24일
for i=1:10
if Li_m_full10(i,1)*10^6 ~= Ri_m_full10(i,1)*10^6
% error
error_1 = sprintf( 'Difference In X Coordinate %d Between Left and Right Model Space', i );
disp(error_1)
elseif Li_m_full10(i,3)*10^6 ~= Ri_m_full10(i,3)*10^6
% error
error_2 = sprintf( 'Difference In Z Coordinate %d Between Left and Right Model Space', i );
disp(error_2)
else
end
end
Where
Li_m_full10 =
[15.9811212241544, 20.7151917170739, -41.3158787392910;
-6.21811036412999, 13.5650723523276, -40.8359583400025;
14.7702533518152, -9.41689361653716, -36.6475648350934;
16.7856234567904, 5.44965770745775, -38.5652761874981;
-4.49546718159992, -10.4977549136369, -37.1977822200610;
-5.58443840827459, 23.1514495438229, -42.0048342504297;
10.1458674678489, -3.29370264049584, -37.9925268240093;
10.8958379341580, 4.99817118096055, -38.7136591008241;
6.96457186489267, 16.0885054037253, -40.6268086865610;
-2.21974302416626, 10.6246429546594, -40.3661741974887]
and
Ri_m_full10 =
[15.9811212241544, 20.6926665759825, -41.3158787392910;
-6.21811036412999, 13.5219038409356, -40.8359583400025;
14.7702533518152, -9.43334232312408, -36.6475648350934;
16.7856234567904, 5.48342269300826, -38.5652761874981;
-4.49546718159991, -10.4862449523353, -37.1977822200610;
-5.58443840827459, 23.1872988430950, -42.0048342504298;
10.1458674678489, -3.27066013992277, -37.9925268240093;
10.8958379341580, 5.01851352020439, -38.7136591008241;
6.96457186489267, 16.0681334029748, -40.6268086865610;
-2.21974302416626, 10.5691345641832 -40.3661741974887]
Errors are printed for all values.
The '~=' in the code doesn't seem to be working for each element i.
  댓글 수: 1
KSSV
KSSV 2016년 10월 24일
You may consider difference of the columns you want to find whether the numbers are different or not.
d1 = Li_m_full10(:,1)-Ri_m_full10(:,1) ;
d2 = Li_m_full10(:,3)-Ri_m_full10(:,3) ;
In the above id d1 or d2 has zeros, then the numbers are equal, if not they are different.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 24일

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by