How do I exclude data coordinates from a preexisting array?
显示 更早的评论
Hello!
I was wondering if anyone could help me, I am working on a project where I have a set of data inside of a matrix and I want to create a new matrix with that data using only points outside of an area defined by two functions.
For example, If I use data=rand(100,2) to create a 100X2 matrix and plot it, there is a seemingly random distribution of points. Let's say I plot y1= .5x+.45 and y2=.5x+.55. There will be some many of points inside of these two functions that I DON'T want to include in my data. How would I go about taking these out of the matrix and how would I go about plotting everything but those points?
I tried doing something like this:
>clear all
>close all
>x=linspace(-1,1,100);
>y=linspace(-1,1,100);
>limit1=.5*x+.45;
>limit2=.5*x+.55;
>data=rand(100,2);
>hold on
>plot(x,limit1);
>plot(x,limit2);
>xlim([0,1]);
ylim([0,1]);
>
>if data(:,2) < transpose(limit1)
>scatter(data(:,1),data(:,2),'r','o');
>if data(:,2) > transpose(limit2)
>scatter(data(:,1),data(:,2),'r','o');
>end
>else scatter(data(:,1),data(:,2),'*');
>end
Unfortunately it doesn't seem like it wants to plot the scatter plots correctly and I have no idea how to even start to remove the elements that don't satisfy the conditions from the array, any help would be greatly appreciated!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!