How to combine graph and merge different array?
Show older comments
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
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
on 29 May 2021
thnx
Süleyman burak Dogaroglu
on 29 May 2021
Edited: Walter Roberson
on 29 May 2021
so could you help me for my code?
function [PQ CRT TSP] = yieldLocus(po, m, stage)
p = 0;
for i = 1 : stage+1
q = sqrt((po*p-p^2));
P(i,1) = p;
PQ(i,1) = p;
PQ(i,2) = q;
CRT(i,1) = p*m;
pf = po + p;
qf = m * pf-50;
TSP(i,1) = pf;
TSP(i,2) = qf;
p = p + po/stage;
end
hold on
plot(PQ,CRT);
plot(TSP);
hold off
end
I want to combine 3 matrix in 1 figure (PQ,CRT and TSP). above the code PQ and CRT matrixes x value does not correct in graph. PQ creates a semi circle and the end of circle x value must be 100 but when i combine them both the circle end at 50. if yo draw the figures seperately that doesn't happen. also combined figure x values plotted like negative x values but also seperated graps does't.
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
on 29 May 2021
When you "hold on" you freeze the xlim and ylim. So after you plot, do
xlim auto
ylim auto
Categories
Find more on Graph and Network Algorithms 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!