How to combine graph and merge different array?

4 views (last 30 days)
KH
KH on 23 Jun 2013
Commented: Walter Roberson on 29 May 2021
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.

Answers (1)

Eli Duenisch
Eli Duenisch on 23 Jun 2013
Edited: Eli Duenisch on 23 Jun 2013
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 Comments
Süleyman burak Dogaroglu
Süleyman burak Dogaroglu on 29 May 2021
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
Walter Roberson on 29 May 2021
When you "hold on" you freeze the xlim and ylim. So after you plot, do
xlim auto
ylim auto

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!