필터 지우기
필터 지우기

matlab returns 'Error using <='

조회 수: 2 (최근 30일)
Bharat
Bharat 2015년 6월 26일
댓글: Walter Roberson 2015년 6월 26일
Hello guys, I need help with a script. I have a function which contains the following commands:
l = Y(abs(X-Sal)<0.0000001)
p = Y(Y <= l & X>=(Sal-0.00001))
When I run, I get the following error: Error using <= Matrix dimensions must agree. However, the same script when run in the command window gives the right result. What am I doing wrong?
Thanks

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 26일
At the command window command
dbstop if error
and run the function. When it stops because of the error, look at size(Y) and size(l) . I suspect you will find that l is either empty or else has multiple elements.
What promises can you make that there will always be exactly 1 location where abs(X-Sal)<0.0000001 ?
  댓글 수: 2
Bharat
Bharat 2015년 6월 26일
Hi Walter, Yes the l is a zero by one matrix. But I don't understand why is that happening? Regarding the 1 location thing, Sal was defined as Sal = X(3); However as abs(X=Sal) doesn't work (a problem with the number of significant digits) , I defined l as such. (I also know that the values of X do differ by atleast 0.01 which makes l exactly one value).
Walter Roberson
Walter Roberson 2015년 6월 26일
You should command
format long g
and then look at the value of Sal and at the values stored in X. You should also examine the values of (X-Sal) to see what the magnitude of the difference is. If your values are above about 10^8 then the difference between consecutive double precision numbers would be more than 0.0000001; look at eps(Sal) to see the distance between adjacent numbers in that range (and realize that it is common for calculations to differ by 10*eps)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by