如何用轴子图将这个Matlab 2014代码重写为2016? [英] How to rewrite this Matlab 2014 code with axis-subplots to 2016?
本文介绍了如何用轴子图将这个Matlab 2014代码重写为2016?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为Matlab 2014编写的代码,但我想将其重写为Matlab 2016,以使其变得更加紧凑,因为它现在变得多余了
Code which I wrote for Matlab 2014 but which I want to rewrite it to Matlab 2016 such that it becomes more compact, since it is extranous now
hFig3=figure('Units', 'inches');
hax3_b1=axes('Parent', hFig3);
hax3_b2=axes('Parent', hFig3);
hax3_b3=axes('Parent', hFig3);
hax3_b4=axes('Parent', hFig3);
b1=subplot(2,2,1, hax3_b1);
b2=subplot(2,2,2, hax3_b2);
b3=subplot(2,2,3, hax3_b3);
b4=subplot(2,2,4, hax3_b4);
% Example of common expression
set([b1 b2], 'Units', 'inches'); % http://stackoverflow.com/a/39817473/54964
u=0:0.1:1; y=sin(u); C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(b1, u, y, C);
hold on;
plot(b2, u');
histogram(b3, u');
histogram(b4, u);
hold off;
drawnow;
输出正常
操作系统:Debian 8.5 64位
MATLAB:2014,但希望转换为2016
OS: Debian 8.5 64 bit
MATLAB: 2014 but want to convert to 2016
推荐答案
您可以简单地编写:
figure('Units','inches');
b1 = subplot(2,2,1);
b2 = subplot(2,2,2);
b3 = subplot(2,2,3);
b4 = subplot(2,2,4);
,或者,如果要具有轴数组,则最好:
or preferably, if you want to have an array of the axes:
figure('Units','inches');
b(1) = subplot(2,2,1);
b(2) = subplot(2,2,2);
b(3) = subplot(2,2,3);
b(4) = subplot(2,2,4);
或使用简单的for
循环:
figure('Units','inches');
b(1:4) = axes;
for k = 1:numel(b)
b(k) = subplot(2,2,k);
end
在任何选择的选项中,都不需要所有axes
命令.
In any option you choose there is no need for all the axes
commands.
这是您的所有演示"代码:
Here is all your 'demo' code:
b(1:4) = axes;
for k = 1:numel(b)
b(k) = subplot(2,2,k);
end
set(b(1:2), 'Units', 'inches');
u=0:0.1:1; y=sin(u); C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(b(1), u, y, C);
plot(b(2), u');
histogram(b(3), u');
histogram(b(4), u);
figure
命令中可能也没有真正的需要,这取决于如何处理.
There might be no real need also in the figure
command, it depends on what do with it.
这篇关于如何用轴子图将这个Matlab 2014代码重写为2016?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文