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!