I need to plot cos-function and choose a n points on the plot.
I have plot a cos function as
x = -pi:0.01:pi;
y=cos(x);
plot(x,y)
As a result I have gotten a cos-plot and a set of (x,y). How can I define , for example, 4 points on this function?
I was thinking to define a vector with y and by using randi(y) and loop , define n number of y:
for i = 1:n
ind = randperm(numel(y), 1);
r(i) = y(ind);
end
It gives me a random choice of the points. BUT I need define equal number of point from both side, if the number of point should be even and if it is odd, one point is on the centre.
For example: if i choose 4 points, 2 point will be on the left side, 2 is on the right side. If the number of point is 5, then one is on the top/middle , 2 point will be on the left side, 2 is on the right side.
How can I implement it in matlab?
Aucun commentaire:
Enregistrer un commentaire