Hey everyone, I've been using matlab for about a month, so this might be a pretty simple question.
I have a vector x=[-3.5 -5 6.2 11 0 8.1 -9 0 3 -1 3 2.5], and I want to make two other vectors from it using a for loop. The first contains the positive elements of x, and the second contains the negative elements of x. I can get it to return individual elements, but not vectors. Your help is greatly appreciated, I've been trying to figure this out for a couple hours.
Heres my code
x=[-3.5 -5 6.2 11 0 8.1 -9 0 3 -1 3 2.5];
n=length(x);
for k=1:n
if x(k)>0
P=x(k)
elseif x(k)<0 N=x(k) endend
Best Answer