필터 지우기
필터 지우기

Subtraction of negative matrix element

조회 수: 4 (최근 30일)
Michael
Michael 2018년 8월 12일
댓글: Michael 2018년 8월 15일
Hello
My data (X,Y) and I am trying to find the distance between the Y value of two points. My issue results from the negative Y value of one of the points. Concept A =1; B =-3; C= A-B; -->4 However, I keep getting an error message
% line 1 has the following values
0 0.750000000000000
0 0
0 -0.500000000000000
0 -0.750000000000000
% Subtraction method
DistX2 = minus(line1 (1,2), line (3,2));
DistX2 = (line1 (1,2) - line (3,2));
% error code
Undefined operator '-' for input arguments of type 'matlab.graphics.primitive.Line'.
Error in PlotCurve (line 50)
DistX2 = minus(line1 (1,2), line (3,2));
  댓글 수: 1
Stephen23
Stephen23 2018년 8월 12일
편집: Stephen23 2018년 8월 12일
@Michael: a line object is not a numeric array. They cannot be "subtracted" in any meaningful way. You could get the Ydata values and subtract those. But most likely it would be simpler and easier to just subtract the values that you used to create the line object: so how did you create this line object?
Do NOT call your variable line, as this shadows the very important inbuilt line function.

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

채택된 답변

Image Analyst
Image Analyst 2018년 8월 12일
line() is a built-in function and you are not using it correctly. Do not use built-in function names for names of your variables. Call it line2 or something instead of line.
  댓글 수: 1
Michael
Michael 2018년 8월 15일
Thanks, Yes I agree that it should be callled something else the second term should be named differently. It was supposed to have read
DistX2 = minus(line1 (1,2), line1 (3,2));
However, cut and paste plus editing resulted in it being missed and the error code just wasn't descriptive enough for me to pick out.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by