When plotting multiple subplots in the for loop, how do you stop the axes from overlapping?
I am trying to plot the suplots in the for loop using the following code:
for k = 1:length(txt_files)
% some code
if PWM_switch == 1
ax1 = axes(t);
ax1.Layout.Tile = Test_Case;
if mod_switch == 1
if OpenLoop == 0
plot(table.data(:,1), table.data(:,2), ‘k’); hold on;
elseif OpenLoop == 1
plot(table.data(:,1), table.data(:,2), ‘k–‘); hold on;
end
end
if mod_switch == 4
if OpenLoop == 0
plot(table.data(:,1), table.data(:,2), ‘r’); hold on;
elseif OpenLoop == 1
plot(table.data(:,1), table.data(:,2), ‘r–‘); hold on;
end
end
end
end
but it appears that every time ax1 = axes(t) is executed, the supplot gets overlapping. You can still see old y-axis scales, but only the latest plots. When I run the loop step-by-step, all plots are plotted in the correct subplots; only they are overlapping.
I need to switch between subplots based on the conditions, i.e., Test Cases.
ax1.Layout.Tile = Test_Case correctly locates the subplot.
The full code with all *.txt files is in the attachment.I am trying to plot the suplots in the for loop using the following code:
for k = 1:length(txt_files)
% some code
if PWM_switch == 1
ax1 = axes(t);
ax1.Layout.Tile = Test_Case;
if mod_switch == 1
if OpenLoop == 0
plot(table.data(:,1), table.data(:,2), ‘k’); hold on;
elseif OpenLoop == 1
plot(table.data(:,1), table.data(:,2), ‘k–‘); hold on;
end
end
if mod_switch == 4
if OpenLoop == 0
plot(table.data(:,1), table.data(:,2), ‘r’); hold on;
elseif OpenLoop == 1
plot(table.data(:,1), table.data(:,2), ‘r–‘); hold on;
end
end
end
end
but it appears that every time ax1 = axes(t) is executed, the supplot gets overlapping. You can still see old y-axis scales, but only the latest plots. When I run the loop step-by-step, all plots are plotted in the correct subplots; only they are overlapping.
I need to switch between subplots based on the conditions, i.e., Test Cases.
ax1.Layout.Tile = Test_Case correctly locates the subplot.
The full code with all *.txt files is in the attachment. I am trying to plot the suplots in the for loop using the following code:
for k = 1:length(txt_files)
% some code
if PWM_switch == 1
ax1 = axes(t);
ax1.Layout.Tile = Test_Case;
if mod_switch == 1
if OpenLoop == 0
plot(table.data(:,1), table.data(:,2), ‘k’); hold on;
elseif OpenLoop == 1
plot(table.data(:,1), table.data(:,2), ‘k–‘); hold on;
end
end
if mod_switch == 4
if OpenLoop == 0
plot(table.data(:,1), table.data(:,2), ‘r’); hold on;
elseif OpenLoop == 1
plot(table.data(:,1), table.data(:,2), ‘r–‘); hold on;
end
end
end
end
but it appears that every time ax1 = axes(t) is executed, the supplot gets overlapping. You can still see old y-axis scales, but only the latest plots. When I run the loop step-by-step, all plots are plotted in the correct subplots; only they are overlapping.
I need to switch between subplots based on the conditions, i.e., Test Cases.
ax1.Layout.Tile = Test_Case correctly locates the subplot.
The full code with all *.txt files is in the attachment. plotting, subplot, axes MATLAB Answers — New Questions