我有以下脚本:
clc;
rawdata =[-25.5565582895276,-42.0420929772342,-57.4408326339985,-59.7565301992094,-78.2941943930302,-98.1668602359215,-100.343039046975,-121.699486271944,-141.606081821085,25.5269655026408,18.5992045105020,10.5565805754708,3.53260099752686,-4.28841814138126,-16.1811680297201,-20.7587597909015,-33.9496739676845,-49.4224591561864,57.8328511599123,52.3046655823801,46.7013172524860,39.5162221274009,33.7256224641108,27.7452068985406,19.8652812098459,13.5106514996026,6.79453063053692,13.7433929003726,2.97742393964905,-11.8788126421713,-14.7842978054585,-28.9344808491738,-45.3735073619029,-46.8956785322602,-62.6359917514933,-79.8733981491996,61.2490778343082,54.8034160582216,48.3178134510063,41.5504174432409,34.7518620160764,27.8634727114719,20.3261327807446,13.0337982439711,5.49160965545350,97.9839091997130,92.6600864270001,87.1620311060214,80.6280629406775,75.0998773631453,69.5716917856131,62.6602847059702,56.8870048045082,51.1137249030461,47.4769977706179,39.2979280037062,30.3814539318442,24.1294173599573,15.2521361570370,3.78877209476342,-1.35049073272485,-13.9729496503441,-28.0870809325725,99.1225647745761,92.8673831076013,86.6122014406265,80.4607759721693,74.0979131702281,67.6123105630128,60.8487400074157,54.3631374002004,47.6598203670550,141.078056536635,135.754233763922,130.430410991209,124.736048048756,119.412225276043,113.995797996904,107.461829831560,101.933644254028,96.4054586764955];
data = transpose(rawdata);
[y1,x1] = hist(data,40);
[y2,x2] = ecdf(data);
subplot(2,1,1)
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
grid; grid minor;
title('Histogram of Data');
ylabel('Count')
xlabel('Data, Unit');
subplot(2,1,2)
pd1 = fitdist(data,'Normal')
pd2 = fitdist(data,'Logistic')
y1 = pdf(pd1,data_values);
y2 = pdf(pd2,data_values);
plot(npv_values,y1); hold on
plot(npv_values,y2);
hold off
title(['Distribution Fitting']);
ylabel('Count')
xlabel('Data, Unit');
legend(pd1.DistributionName,pd2.DistributionName);
grid; grid minor;
生成此图表: subplot charts
然而,我想让第二个子图也用直方图绘制双轴(作为顶部图表)与2个分布拟合图表相结合。 使用下面修改过的脚本,我收到了一个错误。
修改过的脚本:
clc;
rawdata =[-25.5565582895276,-42.0420929772342,-57.4408326339985,-59.7565301992094,-78.2941943930302,-98.1668602359215,-100.343039046975,-121.699486271944,-141.606081821085,25.5269655026408,18.5992045105020,10.5565805754708,3.53260099752686,-4.28841814138126,-16.1811680297201,-20.7587597909015,-33.9496739676845,-49.4224591561864,57.8328511599123,52.3046655823801,46.7013172524860,39.5162221274009,33.7256224641108,27.7452068985406,19.8652812098459,13.5106514996026,6.79453063053692,13.7433929003726,2.97742393964905,-11.8788126421713,-14.7842978054585,-28.9344808491738,-45.3735073619029,-46.8956785322602,-62.6359917514933,-79.8733981491996,61.2490778343082,54.8034160582216,48.3178134510063,41.5504174432409,34.7518620160764,27.8634727114719,20.3261327807446,13.0337982439711,5.49160965545350,97.9839091997130,92.6600864270001,87.1620311060214,80.6280629406775,75.0998773631453,69.5716917856131,62.6602847059702,56.8870048045082,51.1137249030461,47.4769977706179,39.2979280037062,30.3814539318442,24.1294173599573,15.2521361570370,3.78877209476342,-1.35049073272485,-13.9729496503441,-28.0870809325725,99.1225647745761,92.8673831076013,86.6122014406265,80.4607759721693,74.0979131702281,67.6123105630128,60.8487400074157,54.3631374002004,47.6598203670550,141.078056536635,135.754233763922,130.430410991209,124.736048048756,119.412225276043,113.995797996904,107.461829831560,101.933644254028,96.4054586764955];
data = transpose(rawdata);
[y1,x1] = hist(data,40);
[y2,x2] = ecdf(data);
subplot(2,1,1)
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
grid; grid minor;
title('Histogram of Data');
ylabel('Count')
xlabel('Data, Unit');
pd1 = fitdist(data,'Normal');
pd2 = fitdist(data,'Logistic');
data_values = -150:1:150;
c1 = pdf(pd1,data_values);
c2 = pdf(pd2,data_values);
subplot(2,1,2)
[y1,x1] = hist(data,40);
[y2,x2] = plot(data_values,c1);
plot(data_values,c1);
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
hold on
plot(data_values,c2)
hold off
title(['Distribution Fitting']);
ylabel('Count')
xlabel('Data, Unit');
legend(pd1.DistributionName,pd2.DistributionName);
grid; grid minor;
错误消息:
One or more output arguments not assigned during call to "plot".
Error in DATAHistogram_v2 (line 28)
[y2,x2] = plot(data_values,c1);
感谢任何帮助。 感谢。