[Solved] How to rewrite this Matlab 2014 code with axis-subplots to 2016?


You can simply write:

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);

or use a simple for loop:

figure('Units','inches');
b(1:4) = axes;
for k = 1:numel(b)
    b(k) = subplot(2,2,k);
end

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);

There might be no real need also in the figure command, it depends on what do with it.

4

solved How to rewrite this Matlab 2014 code with axis-subplots to 2016?