axeshandle with matlab code

2 views (last 30 days)
MattC
MattC on 7 Mar 2023
Answered: Image Analyst on 7 Mar 2023
Hi, I have 4 plots in total which I trying to plot using axeshandle, subplot but for some reason I only 3 plots the first plot is missing. Please help how to fix this
%First plot
axeshandle(1)=subplot('position',[0.13 .808 .775 .097]);
plot (A_Table1.Time,A_Table1_Var1, '*')
% Second plot which has 3 plots in itself
Days = datetime(['03/06/2023';'03/07/2023'], 'InputFormat','MM/dd/yyyy', 'Format','MM/dd/yyyy');
Data = array2table([5 50; 50 40; 55 65], 'VariableNames',string(Days), 'RowNames',{'A','B','C'})
axeshandle(2)=subplot('position',[0.13 .641 .775 .106]);
VN = Data.Properties.VariableNames;
Rows = Data.Properties.RowNames;
tiledlayout(3,1)
for k = 1:3
nexttile
plot(categorical(VN), table2array(Data(k,:)))
title(Rows{k})
ylim([0 100])
end

Answers (2)

Walter Roberson
Walter Roberson on 7 Mar 2023
You need to stick to using subplot() or using tiledlayout() -- mixing the two can be a challenge.
You have five plots, not four, by the way. You subplot() for axeshandle1, then you subplot() for axeshandle2, then you nexttile for three plots -- a total of five axes.
  1 Comment
MattC
MattC on 7 Mar 2023
Sorry I new to this and I think I am just trying to achieve 4 subplots
1 for first plot
3 for second plot
I am not stuck to any 1 approach. I am flexible to using subplot or tiledlayout but do not know how to implement this.

Sign in to comment.


Image Analyst
Image Analyst on 7 Mar 2023
Try it this way
% First plot on first axes
subplot(2, 1, 1); % Create second axes.
plot(rand(1,10), 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
title('The first axes has 1 curve plotted')
grid on;
% First plot on second axes
subplot(2, 1, 2); % Create second axes.
plot(rand(1,10), 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
% Second plot on second axes
hold on; % Don't blow away prior plots on this axes.
plot(rand(1,10), 'r.-', 'LineWidth', 2, 'MarkerSize', 20);
% Third plot on second axes
plot(rand(1,10), 'g.-', 'LineWidth', 2, 'MarkerSize', 20);
legend
hold off;
grid on;
title('The second axes has 3 curves plotted')

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!