How to combine graph and merge different array?
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi all,
Can someone help me with this?
Let's say I have in an m-file two corresponding array of a = [2 3 5 9 10 20 27 34] & b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8] and have a graph of a vs b
and in another m-file i have array of c = [67 79 80 99] & corresponding array d = [1.0 1.1 1.2 1.3] and a graph of c vs d
How to I join the graph together since i'll don't have a value for 0.9 in the x-axis? Secondly, how can I combine both both a & c vector in the same array and b & d in the same array?
Thanks a lot.
댓글 수: 0
답변 (1개)
Eli Duenisch
2013년 6월 23일
편집: Eli Duenisch
2013년 6월 23일
Why do you want to combine the vectors a&a, b&d if you want to plot two graphs? If your goal is to plot two graphs into one axis, try this:
Get the data into one workspace: If both m files are scripts, just run the scripts. If one of the m-file is a function you can pass the arrays it contains to the other m-file as return values. You can also make both files functions. Or maybe use a third file for the plot code.
Plotting two graphs into one axis: Lets say all of your arrays are in the same workspace. Now you have various possibilities to plot the graph:
hold on
plot(a,b)
plot(c,d)
hold off
Or with two y axis use:
plotyy(a,b,c,d)
댓글 수: 4
Süleyman burak Dogaroglu
2021년 5월 29일
I suppose solved like;
function [PQ CRT TSP] = yieldLocus(po, m, stage)
p = 0;
dp = 0;
for i = 1 : stage+100
q = sqrt((po*p-p^2)*m^2);
P(1,i) = p;
PQ(1,i) = q;
p = p + po/stage;
end
for j = 1 : stage+100
pf = po + dp;
DP(1,j) = pf;
qf = 3 * dp;
TSP(1,j) = qf;
dp = dp + po/stage;
end
p_ = 0;
for k = 1 : stage+100
CRT(1,k) = p_*m;
p_ = p_ + po/stage;
end
hold on
plot(P,PQ,'r');
plot(P,CRT,'g');
plot(DP,TSP,'b');
hold off
end
Walter Roberson
2021년 5월 29일
When you "hold on" you freeze the xlim and ylim. So after you plot, do
xlim auto
ylim auto
참고 항목
카테고리
Help Center 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!