Issue with plotting two figures using for-loop method

조회 수: 1 (최근 30일)
Paulino
Paulino 2023년 10월 6일
편집: MarKf 2023년 10월 6일
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);
Unable to resolve the name '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개)

MarKf
MarKf 2023년 10월 6일
편집: MarKf 2023년 10월 6일
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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by