Write a matlab code that generates a one dimensional array o

Write a matlab code that generates a one dimensional array of random numbers (positive and negative) of dimension 20. Then perform the following: Using a for command and if command collect the positive values in another array called pos and the negative values in another array called neg.

Solution

clc
randomarray = -1 + 2 * rand(10,1)
j=1
k=1
for i = 1:10
if (randomarray(i)<0)
neg(j)=randomarray(i);
j=j+1;
else
pos(k)=randomarray(i);
k=k+1;
end
end
pos
neg

Write a matlab code that generates a one dimensional array of random numbers (positive and negative) of dimension 20. Then perform the following: Using a for co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site