Issue with plotting two figures using for-loop method
Afficher commentaires plus anciens
Hi all,
I am trying to plot two figures with 'for' loop but the second figure comes shortened for some reason.
Thanks in advance!
Units = unique(WTG_ALL.Unit);
n_units = numel(Units);
for ii = 1:length(Units);
selected_unit = Units{ii};
is_selected_unit = strcmpi(WTG_ALL_shaft.Unit, selected_unit);
WTG_ALL_filtered = WTG_ALL_shaft(is_selected_unit, :);
figure(ii); hold on;
subplot(1, 4, 1); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.Xu_shear, WTG_ALL_filtered.layer_mid, 'o');
xlabel('pu');
ylabel('Layer Midpoint Depth');
title('pu');
subplot(1, 4, 2); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.Ktan_shear, WTG_ALL_filtered.layer_mid, 'o');
xlabel('ktan');
ylabel('Layer Midpoint Depth');
title('ktan');
subplot(1, 4, 3); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.n_shear, WTG_ALL_filtered.layer_mid, 'o');
xlabel('n');
ylabel('Layer Midpoint Depth');
title('n');
subplot(1, 4, 4); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.Yu_shear, WTG_ALL_filtered.layer_mid, 'o');
xlabel('yu');
ylabel('Layer Midpoint Depth');
title('yu');
print(gcf,['Output/',selected_unit,'p_y_.png'],'-dpng','-r150');
end
for ii=1:length(Units);
selected_unit = Units{ii};
is_selected_unit = strcmpi(WTG_ALL_shaft.Unit, selected_unit);
WTG_ALL_filtered = WTG_ALL_shaft(is_selected_unit, :);
figure(ii+n_units);
subplot(2, 4, 1); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.Xu_moment, WTG_ALL_filtered.layer_mid, 'o');
xlabel('mu');
ylabel('Layer Midpoint Depth');
title('mu');
subplot(2, 4, 2); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.Ktan_moment, WTG_ALL_filtered.layer_mid, 'o');
xlabel('Ktan');
ylabel('Layer Midpoint Depth');
title('ktan');
subplot(2, 4, 3); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.n_moment, WTG_ALL_filtered.layer_mid, 'o');
xlabel('n');
ylabel('Layer Midpoint Depth');
title('n');
subplot(2, 4, 4); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.Yu_moment, WTG_ALL_filtered.layer_mid, 'o');
xlabel('theta u');
ylabel('Layer Midpoint Depth');
title('theta u');
print(gcf,['Output/',selected_unit,'m_theta_.png'],'-dpng','-r150');
end
1 commentaire
Réponses (1)
Do you just mean that the second figure is half as high because you did subplot(2, 4,...) in the second part instead of subplot(1, 4,...) as in the first part?
Units = 10;
srstrs = {'Xu' 'Ktan' 'n' 'Yu'};
for sti = 1:numel(srstrs)
WTG_ALL_filtered.([srstrs{sti} '_shear']) = randi(Units, Units);
WTG_ALL_filtered.([srstrs{sti} '_moment']) = randi(Units, Units);
end
WTG_ALL_filtered.layer_mid = randi(Units, Units); % just fabricated as an example since you did not provide data
n_units = numel(Units);
for ii = 1:length(Units);
% selected_unit = Units{ii};
% is_selected_unit = strcmpi(WTG_ALL_shaft.Unit, selected_unit);
% WTG_ALL_filtered = WTG_ALL_shaft(is_selected_unit, :);
figure(ii); hold on;
for sti = 1:numel(srstrs)
subplot(1, 4, sti); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.([srstrs{sti} '_shear']), WTG_ALL_filtered.layer_mid, 'o');
xlabel(srstrs{sti} );
ylabel('Layer Midpoint Depth');
title(srstrs{sti} );
end
% print(gcf,['Output/',selected_unit,'p_y_.png'],'-dpng','-r150');
end
for ii=1:length(Units);
% selected_unit = Units{ii};
% is_selected_unit = strcmpi(WTG_ALL_shaft.Unit, selected_unit);
% WTG_ALL_filtered = WTG_ALL_shaft(is_selected_unit, :);
figure(ii+n_units);
for sti = 1:numel(srstrs)
subplot(2, 4, sti); hold on;
set(gca, 'Ydir', 'reverse', 'XAxisLocation', 'top');
plot(WTG_ALL_filtered.([srstrs{sti} '_moment']), WTG_ALL_filtered.layer_mid, 'o');
xlabel(srstrs{sti});
ylabel('Layer Midpoint Depth');
title([srstrs{sti} ' moment']);
end
end
Catégories
En savoir plus sur L*a*b* Color Space dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

