Question about variable in a vector.

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 Comments

Azzi Abdelmalek
Azzi Abdelmalek on 20 Sep 2012
Edited: Azzi Abdelmalek on 20 Sep 2012
Z(n)~=Z(n) this is always false
and what is your function function_name
Azzi:
z = nan;
z(1)~=z(1)
hum, good to know. Thanks Matt
@James Ortiz: Are you going to delete the text of the question as in your former thread Answers_ 48636? If so, I'm not going to post an answer.
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!]
@matt, ive searched and read tutorials but still cant find a solution to my problem. what should i do. :(

Sign in to comment.

Answers (2)

Matt Fig
Matt Fig on 20 Sep 2012
Edited: Matt Fig on 20 Sep 2012
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 on 21 Sep 2012
@Jan Simon, sorry about that. wont do it again. :(

2 Comments

Fine, thanks. Please post comments to comments as comments and not as answer of a question.
sorry. im not yet used to using this page. can you help me with the code. :(

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Asked:

on 20 Sep 2012

Community Treasure Hunt

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

Start Hunting!