0
votes

in this code I create a random vector with 100 values and I want to get two vector out of it: one with all the values under 1 and one with all the value above 1. I created this code, which works, but I wonder if there is a more efficient one, without to have the 2 vectors filled with 0

clear all, close all, clc;
%% ficiional vector creation
%
a=0;
b=10;
v1=(b-a).*rand(100,1);
i=1;
while i<length(v1)  

if v1(i)>1
    x(i)=v1(i);
end
if v1(i)<1
        y(i)=v1(i);
end

        i=i+1;
end
x(x==0)=[];
y(y==0)=[];

thank you!

1

1 Answers

0
votes
a=0;
b=10;
v1=(b-a).*rand(100,1);
x=v1(v1>1);
y=v1(v1<1);