masking data plots for graph

조회 수: 16 (최근 30일)
cvbnm
cvbnm 2017년 11월 18일
댓글: cvbnm 2017년 11월 18일
I want my plot to include my mask:
mask=true(size(x));
mask(0>x)=false;
mask=true(size(y));
mask(0>y)=false;
plot(x(mask),y(mask),'.')
It is not a problem, when I only have to mask the x values or y values seperately, only when I have to plot both masks.
Could the problem be that my mask for x and y respectively aren't having a particular definition? I tried with 'xmask' and 'ymask' and add this to the plotting sequence, but it does not work either.

답변 (2개)

Walter Roberson
Walter Roberson 2017년 11월 18일
xt = x;
xt(xt<0) = nan;
yt = y;
yt(yt<0) = nan;
plot(xt, yt);
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 11월 18일
mask = (x > 0) & (y > 0);
[b,stats]=robustfit(x(mask),y(mask));
However, this is only going to work if x and y are vectors. If they are 2D then the result of x(mask) and y(mask) is going to be a column vector, because 2D arrays cannot have "holes" in them.
cvbnm
cvbnm 2017년 11월 18일
They are not vectors, so that is maybe why it doesn't work, unfortunately. I added my original code below, just in case my reply to you would be confusing. Does this mean that I can not fit data, with I mask values for both the x- and y-axis?

댓글을 달려면 로그인하십시오.


cvbnm
cvbnm 2017년 11월 18일
편집: Walter Roberson 2017년 11월 18일
My original code for fitting was:
[b,stats]=robustfit(x(mask),y(mask));
x1=[min(x(mask)),max(x(mask))];
y1= b(1)+b(2)*x1;
hold on
plot(x(mask),y(mask),'.b');
plot(x1,y1,'-r');
This is used for plotting my data and the fitting. When I use both of the two masks, it can not fit my data. There is no problem when I only masks one of the variables (either x or y).

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by