Plot two figures simultaneously
6 次查看(过去 30 天)
显示 更早的评论
I would like to know how to generate this two graphs from this code at the same time:
close all
clear all
clc
format long
%% Data Layup
Layup = [90 0 0 45 -45 0 0 -45 45 0 0 90];
Dimensions_Ply = [100 100 0.125]; % [mm]; x,y,z of individual ply
Total_Thickness = sum(Dimensions_Ply(3)*ones(length(Layup),1)); % Could change if the meterials are not the same
%
x_dimension = Dimensions_Ply(1);
y_dimension = Dimensions_Ply(2);
z_dimension = Dimensions_Ply(3);
%% 3D Laminate generator
for i = 1:length(Layup)
if Layup(i) == 90
C(i) = {'r'}; % 90º = red
elseif Layup(i) == 0
C(i) = {'g'}; % 0º = green
elseif Layup(i) == 45
C(i) = {'b'}; % 45º = blue
elseif Layup(i) == -45
C(i) = {'c'}; % -45º = cyan
end
end
%%%%%%%%%%%%%%%%%%%%%%%
% movegui(f1,'west');
% get(0,'DefaultFigurePosition')
figure('Position',[110 206 560 420])
for n = 1:length(Layup)
coord = [... % Creating plies coordinates depending on dimensions
0 0 (n-1)*z_dimension;
x_dimension 0 (n-1)*z_dimension;
x_dimension y_dimension (n-1)*z_dimension;
0 y_dimension (n-1)*z_dimension;
0 0 ((n-1)*z_dimension) + z_dimension;
x_dimension 0 ((n-1)*z_dimension) + z_dimension;
x_dimension y_dimension ((n-1)*z_dimension) + z_dimension;
0 y_dimension ((n-1)*z_dimension) + z_dimension;];
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
% i = randi(4)
xc = coord(:,1);
yc = coord(:,2);
zc = coord(:,3);
patch(xc(idx), yc(idx), zc(idx),C{n}); % 'facealpha', 0.1
%
set(gca, 'XDir','reverse') % mAINTAIN perspective
set(gca, 'YDir','reverse')
%
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
hold on
title ('Isometric View')
% Creating the color legend
colors = ['r';'g';'b';'c'];
nColors=size(colors,1); % make variable so can change easily
labels={'90º';'0º';'45º';'-45º'};
hBLG = bar(nan(2,nColors)); % the bar object array for legend
for i=1:nColors
hBLG(i).FaceColor=colors(i,:);
end
legend(hBLG,labels,'location','northeast');
%
view(3);
%
drawnow
pause(0.002) % Speed of the drawing
%
hold off
end
figure('Position',[690 206 560 420])
for n = 1:length(Layup)
coord = [... % Creating plies coordinates depending on dimensions
0 0 (n-1)*z_dimension;
x_dimension 0 (n-1)*z_dimension;
x_dimension y_dimension (n-1)*z_dimension;
0 y_dimension (n-1)*z_dimension;
0 0 ((n-1)*z_dimension) + z_dimension;
x_dimension 0 ((n-1)*z_dimension) + z_dimension;
x_dimension y_dimension ((n-1)*z_dimension) + z_dimension;
0 y_dimension ((n-1)*z_dimension) + z_dimension;];
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
% i = randi(4)
xc = coord(:,1);
yc = coord(:,2);
zc = coord(:,3);
patch(xc(idx), yc(idx), zc(idx),C{n}); % 'facealpha', 0.1
%
set(gca, 'XDir','reverse') % mAINTAIN perspective
set(gca, 'YDir','reverse')
%
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
hold on
legend(hBLG,labels,'location','northeast');
title ('Front-side View')
% Creating the color legend
colors = ['r';'g';'b';'c'];
nColors=size(colors,1); % make variable so can change easily
labels={'90º';'0º';'45º';'-45º'};
hBLG = bar(nan(2,nColors)); % the bar object array for legend
for i=1:nColors
hBLG(i).FaceColor=colors(i,:);
end
legend(hBLG,labels,'location','northeast');
%
view(90,0);
%
drawnow
pause(0.002)
%
hold off
end
0 个评论
采纳的回答
DGM
2022-4-26
You can try something like this. There's some lag in between figure updates, but it's a start.
% Data Layup
Layup = [90 0 0 45 -45 0 0 -45 45 0 0 90];
Dimensions_Ply = [100 100 0.125]; % [mm]; x,y,z of individual ply
Total_Thickness = sum(Dimensions_Ply(3)*ones(length(Layup),1)); % Could change if the meterials are not the same
x_dimension = Dimensions_Ply(1);
y_dimension = Dimensions_Ply(2);
z_dimension = Dimensions_Ply(3);
% 3D Laminate generator
for i = 1:length(Layup)
if Layup(i) == 90
C(i) = {'r'}; % 90º = red
elseif Layup(i) == 0
C(i) = {'g'}; % 0º = green
elseif Layup(i) == 45
C(i) = {'b'}; % 45º = blue
elseif Layup(i) == -45
C(i) = {'c'}; % -45º = cyan
end
end
hf1 = figure('Position',[110 206 560 420]);
title ('Isometric View')
hf2 = figure('Position',[690 206 560 420]);
title ('Front-side View')
for n = 1:length(Layup)
coord = [... % Creating plies coordinates depending on dimensions
0 0 (n-1)*z_dimension;
x_dimension 0 (n-1)*z_dimension;
x_dimension y_dimension (n-1)*z_dimension;
0 y_dimension (n-1)*z_dimension;
0 0 ((n-1)*z_dimension) + z_dimension;
x_dimension 0 ((n-1)*z_dimension) + z_dimension;
x_dimension y_dimension ((n-1)*z_dimension) + z_dimension;
0 y_dimension ((n-1)*z_dimension) + z_dimension;];
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
figure(hf1)
updatefig(coord,idx,n,C,1)
figure(hf2)
updatefig(coord,idx,n,C,2)
%pause(0.002)
end
function updatefig(coord,idx,n,C,dispstyle)
xc = coord(:,1);
yc = coord(:,2);
zc = coord(:,3);
patch(xc(idx), yc(idx), zc(idx),C{n}); % 'facealpha', 0.1
set(gca, 'XDir','reverse') % mAINTAIN perspective
set(gca, 'YDir','reverse')
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
hold on
% Creating the color legend
colors = ['r';'g';'b';'c'];
nColors = size(colors,1); % make variable so can change easily
labels = {'90º';'0º';'45º';'-45º'};
hBLG = bar(nan(2,nColors)); % the bar object array for legend
for i = 1:nColors
hBLG(i).FaceColor = colors(i,:);
end
legend(hBLG,labels,'location','northeast');
switch dispstyle
case 1
view(3);
case 2
view(90,0);
end
drawnow
hold off
end
更多回答(1 个)
Mathieu NOE
2022-4-26
hi
my suggestion with subplots
close all
clear all
clc
format long
%% Data Layup
Layup = [90 0 0 45 -45 0 0 -45 45 0 0 90];
Dimensions_Ply = [100 100 0.125]; % [mm]; x,y,z of individual ply
Total_Thickness = sum(Dimensions_Ply(3)*ones(length(Layup),1)); % Could change if the meterials are not the same
%
x_dimension = Dimensions_Ply(1);
y_dimension = Dimensions_Ply(2);
z_dimension = Dimensions_Ply(3);
%% 3D Laminate generator
for i = 1:length(Layup)
if Layup(i) == 90
C(i) = {'r'}; % 90º = red
elseif Layup(i) == 0
C(i) = {'g'}; % 0º = green
elseif Layup(i) == 45
C(i) = {'b'}; % 45º = blue
elseif Layup(i) == -45
C(i) = {'c'}; % -45º = cyan
end
end
%%%%%%%%%%%%%%%%%%%%%%%
% movegui(f1,'west');
% get(0,'DefaultFigurePosition')
figure('Position',[390 106 1093 815])
for n = 1:length(Layup)
%% top plot
coord = [... % Creating plies coordinates depending on dimensions
0 0 (n-1)*z_dimension;
x_dimension 0 (n-1)*z_dimension;
x_dimension y_dimension (n-1)*z_dimension;
0 y_dimension (n-1)*z_dimension;
0 0 ((n-1)*z_dimension) + z_dimension;
x_dimension 0 ((n-1)*z_dimension) + z_dimension;
x_dimension y_dimension ((n-1)*z_dimension) + z_dimension;
0 y_dimension ((n-1)*z_dimension) + z_dimension;];
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
% i = randi(4)
xc = coord(:,1);
yc = coord(:,2);
zc = coord(:,3);
subplot(211),patch(xc(idx), yc(idx), zc(idx),C{n}); % 'facealpha', 0.1
hold on
set(gca, 'XDir','reverse') % mAINTAIN perspective
set(gca, 'YDir','reverse')
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
title ('Isometric View')
% Creating the color legend
colors = ['r';'g';'b';'c'];
nColors=size(colors,1); % make variable so can change easily
labels={'90º';'0º';'45º';'-45º'};
hBLG = bar(nan(2,nColors)); % the bar object array for legend
for i=1:nColors
hBLG(i).FaceColor=colors(i,:);
end
legend(hBLG,labels,'location','northeast');
view(3);
%
%% bottom plot
coord = [... % Creating plies coordinates depending on dimensions
0 0 (n-1)*z_dimension;
x_dimension 0 (n-1)*z_dimension;
x_dimension y_dimension (n-1)*z_dimension;
0 y_dimension (n-1)*z_dimension;
0 0 ((n-1)*z_dimension) + z_dimension;
x_dimension 0 ((n-1)*z_dimension) + z_dimension;
x_dimension y_dimension ((n-1)*z_dimension) + z_dimension;
0 y_dimension ((n-1)*z_dimension) + z_dimension;];
idx = [4 8 5 1 4; 1 5 6 2 1; 2 6 7 3 2; 3 7 8 4 3; 5 8 7 6 5; 1 4 3 2 1]';
% i = randi(4)
xc = coord(:,1);
yc = coord(:,2);
zc = coord(:,3);
subplot(212),patch(xc(idx), yc(idx), zc(idx),C{n}); % 'facealpha', 0.1
hold on
%
set(gca, 'XDir','reverse') % mAINTAIN perspective
set(gca, 'YDir','reverse')
%
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
legend(hBLG,labels,'location','northeast');
title ('Front-side View')
% Creating the color legend
colors = ['r';'g';'b';'c'];
nColors=size(colors,1); % make variable so can change easily
labels={'90º';'0º';'45º';'-45º'};
hBLG = bar(nan(2,nColors)); % the bar object array for legend
for i=1:nColors
hBLG(i).FaceColor=colors(i,:);
end
legend(hBLG,labels,'location','northeast');
%
view(90,0);
%
drawnow
pause(0.002)
%
end
hold off
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!