MATLAB: Help determining values of a vector

functionindexingMATLABmodulus

Hello, I am writing a code that asks the user to input a number a values then takes those values and puts them into an array. Then evaluates each element of the array to determine if it is pos, neg, even, or odd. Here's what I have
function [Poseven]= Vect(UserNum);
str = inputdlg('Enter 10 numbers seperated by spaces or commas');
UserNum = str2num(str{1});
if mod(UserNum, 2) == 0, UserNum > 0;
Poseven = UserNum(1,1:end)
end
end
The only thing I am not understanding is why or how rather to display the numbers of the original vector where the modulus value is zero and greater than zero.

Best Answer

Your lines
if mod(UserNum, 2) == 0, UserNum > 0;
Poseven = UserNum(1,1:end)
end
are the same as
if mod(UserNum, 2) == 0
UserNum > 0;
Poseven = UserNum(1,1:end)
end
which calculates whether UserNum > 0 and then throws away the result of the comparison. If you want to combine conditions, you need to use one of &&, ||, &, or |
Note: you probably want to use either a loop or logical indexing.