필터 지우기
필터 지우기

How to add one scatter plor to another?

조회 수: 1 (최근 30일)
Vasily Kozhevnikov
Vasily Kozhevnikov 2013년 2월 23일
Hello,
I have two pairs of (x,y) arrays, say (x1,y1) and (x2, y2), they have equal length, but may be unordered. Also x1 set intersect x2. For example x1 = [0, 2, 4, 8, 1, 10] and x2 = [2, 9, 11, 13, 5, 7], corresponds to y1 = x1.^4 and y2 = sqrt(x2).
How to scatterplot y1+y2 sum on union of x1 and x2? Thanks.

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 23일
편집: Azzi Abdelmalek 2013년 2월 23일
x=[x1 x2]
y=[y1 y2]
[val,idx]=sort(x);
new_x=val
new_y=y(idx)
plot(new_x,new_y)
  댓글 수: 2
Vasily Kozhevnikov
Vasily Kozhevnikov 2013년 2월 23일
x = [x1 x2] isn't union, and the last command will not plot sum
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 23일
편집: Azzi Abdelmalek 2013년 2월 23일
It's not clear, maybe this:
x=sort(unique([x1 x2]))
y1=x.^4;
y2=sqrt(x)
plot(x,y1+y2)

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


Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 23일
편집: Azzi Abdelmalek 2013년 2월 23일
%or you are looking for
x1 = [0, 2, 4, 8, 1, 10]
x2 = [2, 9, 11, 13, 5, 7],
y1=x1.^4;
idx1=find(ismember(x1,x2)) % find common values in x1 & x2
y1(idx1)=y(idx1)+sqrt(x1(idx1)) %add second function to common values
x2(ismember(x2,x1))=[] % remove common value from x2
y2=sqrt(x2)
[x,idx]=sort([x1 x2])
y=[y1 y2]
y=y(idx)
plot(x,y)

Vasily Kozhevnikov
Vasily Kozhevnikov 2013년 2월 24일
Sorry, but in my task y1 is a list of values, but not an analytic function of x1. But now to my opinion I have a solution
x = union(x1, x2); f = interp1(x1, y1, x, 'cubic', 0) + interp1(x2, y2, x, 'cubic', 0); plot(x, f)
it may works
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 24일
Vasily, in your question y1 and y2 are not a list of object, but functions of x1 and x2.

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

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by