필터 지우기
필터 지우기

Question about variable in a vector.

조회 수: 1 (최근 30일)
Portgas Ace
Portgas Ace 2012년 9월 20일
a part of my program has syntax that looks like this, btw, my goal is to display an error message if i inserted a non-integer value to a vector.
for n=1:1:A1
if (Z(n)<3 | Z(n)>9 | Z(n)~=Z(n))
disp('One or more of the element/s is/are not included.');
return;
elseif ~isnumeric(Z(n))
disp('There is error')
return;
end
end
so if i enter:
function_name ([3 4 A], [4 5 6])
matlab says: Undefined function or variable 'A'.
what should i do for it to run and just display an error message.
  댓글 수: 6
Matt Fig
Matt Fig 2012년 9월 21일
편집: Jan 2012년 9월 21일
OP: a part of my program has syntax that looks like this, btw, my goal is to display an error message if i inserted a non-integer value to a vector.
for n = 1:1:A1
if (Z(n)<3 | Z(n)>9 | Z(n)~=Z(n))
disp('One or more of the element/s is/are not included.');
return;
elseif ~isnumeric(Z(n))
disp('There is error')
return;
end
end
so if i enter:
function_name ([3 4 A], [4 5 6])
matlab says: Undefined function or variable 'A'.
what should i do for it to run and just display an error message.
[EDITED, Jan, code formatted. @James Ortiz: please use one of the many tutorials to learn how to do this by your own. Thanks!]
Portgas Ace
Portgas Ace 2012년 9월 21일
@matt, ive searched and read tutorials but still cant find a solution to my problem. what should i do. :(

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

답변 (2개)

Matt Fig
Matt Fig 2012년 9월 20일
편집: Matt Fig 2012년 9월 20일
You cannot rely on mixing types in a regular array.
[3 4 A]
may return an error message if A is not defined, or if A is not numeric.
A = 6;
[3 4 A] % No error.
As Azzi points out, Z(n) is always equal to Z(n) unless Z(n) is a nan. If you want to deal with nans, use isequalwithequalnans.

Portgas Ace
Portgas Ace 2012년 9월 21일
@Jan Simon, sorry about that. wont do it again. :(
  댓글 수: 2
Jan
Jan 2012년 9월 21일
Fine, thanks. Please post comments to comments as comments and not as answer of a question.
Portgas Ace
Portgas Ace 2012년 9월 21일
sorry. im not yet used to using this page. can you help me with the code. :(

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by