SOS: How do I get the same amount of positive and negative values in a random vector?
Show older comments
I'm a beginner with matlab. I need to make a plot with 2 vectors with both 200 values between -1 and 1. Then I need to select the points with both x & y above 0 and plot this. I tried this:
a = -1;
b = 1;
x = (b-a)*rand(200,1) + a;
y = (b-a)*rand(200,1) + a;
minx = x(x>0);
miny = y(y>0);
plot(minx,miny)
I get the notification that my vectors have different lengths. I think this is because there are not the same amount of negative & positive values. Does anyone know how I can fix this? I've been stuck at it for a really long time.
Accepted Answer
More Answers (1)
Rik
on 26 Sep 2020
Your question differs from your description. If you want to select the points with both x and y above 0, you need to use both as a condition. See this example:
a=[1 5 3 8 40 3];
b=[6 4 2 1 56 2];
clc
L1= a>7
L2= b<5
L=L1&L2
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!