Multiple plots are not showing in my code?

5 ビュー (過去 30 日間)
Danielle
Danielle 2014 年 11 月 6 日
回答済み: Chad Greene 2014 年 11 月 6 日
Hi, so I have to write a code in which I have multiple plots needed to be shown in a single subplot square. I've tried using hold on and figure, and plotting them in a single plot function. When I use hold on, no function shows! But when I plot them all together, only the last one shows. Please, help? I may have used spline wrong, but I just would really like to see the graphic representation of these extrapilations before I fix everything else. Also, I code in script form:
clear clc
x = linspace(0, 4*pi)
y = sin(x)
c = 'yrbgk'
ax = [0, 14, -2, 2]
axis(ax)
l = length(x)
o = l ./ 5
t = (2.*l)./5
th = (3.*l)./5
f = (4.*l)./5
fi = (5.*l)./5
cc = c(1)
cd = c(2)
ce = c(3)
cf = c(4)
cg = c(5)
omg = x(1:o)
zomg = x(1:t)
golly = x(1:th)
gee = x(1:f)
goshers = x(1:fi)
% all five pieces of data and colors %first extrap
subplot(3,1,1)
yout = interp1(x, y, omg, 'linear', 'extrap')
youtu = interp1(x, y, zomg, 'linear', 'extrap')
youtub = interp1(x, y, golly, 'linear', 'extrap')
youtube = interp1(x, y, gee, 'linear', 'extrap')
plot(omg,yout,cc)
hold on
plot(zomg,youtu,cd)
hold on
plot(golly,youtub,ce)
hold on
plot(gee,youtube,cf)
hold on
plot(goshers,y,cg)
figure
xlabel('x values')
ylabel('y values')
title('Interp1: Linear')
%second extrap
subplot(3,1,2)
yout = interp1(x, y, omg, 'cubic', 'extrap')
youtu = interp1(x, y, zomg, 'cubic', 'extrap')
youtub = interp1(x, y, golly, 'linear', 'extrap')
youtube = interp1(x, y, gee, 'cubic', 'extrap')
plot(omg,yout,cc,zomg,youtu,cd,golly,youtub,ce,gee,youtube,cf,goshers,y,cg)
xlabel('x values')
ylabel('y values')
title('Interp2: Cubic')
%third extrap
subplot(3,1,3)
yout = spline(x, y, omg)
youtu = spline(x, y, zomg)
youtub = spline(x, y, golly)
youtube = spline(x, y, gee)
plot(omg,yout,cc,zomg,youtu,cd,golly,youtub,ce,gee,youtube,cf,goshers,y,cg)
xlabel('x values')
ylabel('y values')
title('Interp3: Spline')

採用された回答

Chad Greene
Chad Greene 2014 年 11 月 6 日
It looks like your data are plotted right on top of each other. See:
clear clc
x = linspace(0, 4*pi);
y = sin(x);
c = 'yrbgk'
l = length(x);
o = l ./ 5;
t = (2.*l)./5;
th = (3.*l)./5;
f = (4.*l)./5;
fi = (5.*l)./5;
cc = c(1);
cd = c(2);
ce = c(3);
cf = c(4);
cg = c(5);
omg = x(1:o);
zomg = x(1:t);
golly = x(1:th);
gee = x(1:f);
goshers = x(1:fi);
% all five pieces of data and colors %first extrap
figure
subplot(3,1,1)
yout = interp1(x, y, omg, 'linear', 'extrap')
youtu = interp1(x, y, zomg, 'linear', 'extrap')
youtub = interp1(x, y, golly, 'linear', 'extrap')
youtube = interp1(x, y, gee, 'linear', 'extrap')
plot(omg,yout+1,cc) % <-- * * * HERE I CHANGED IT TO youtu+1 * * *
hold on
plot(zomg,youtu,cd)
A work around would be to plot the shorter snippets of data last, so the longer lines don't perfectly cover them up.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by