Error while concatenating two .stl files
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to combine my two .stl files into one and keep getting this error message "Dimensions of arrays being concatenated are not constant wheras I used virtually the same code for both solids as you can see:
Code 1:
% Clear all previous commands
clear all
close all
clc
figure(2)
% Variables you can change
Sizex = 1; %average length of RVE
Sizey = 1;
Sizez = 1;
Def = 60; %definition
% Variables you shouldn´t change
SFactx = (Sizex/2)/pi; %size factor of RVE
SFacty = (Sizey/2)/pi;
SFactz = (Sizez/2)/pi;
A = SFactx*pi; %lowest and max coordinates of meshgrid
B = SFacty*pi;
C = SFactz*pi;
Dx = A/Def;%definition factor
Dy = B/Def;
Dz = C/Def;
% Generation of gyroids
[X,Y,Z] = meshgrid(-A:Dx:A, -B:Dy:B, -C:Dz:C); %creates mesh grid
% Gyroid equation
OBJ =(cos(X/SFactx).* sin(Y/SFacty) + cos(Y/SFacty).* sin(Z/SFactz)...
+ cos(Z/SFactz).* sin(X/SFactx)+(0));
T = 0.5;
OBJ =(OBJ-T);
% Isosurface and isocap
[F1,V1] = isosurface(X,Y,Z,OBJ,0);
[F2,V2] = isocaps(X,Y,Z,OBJ,0,'below');
%Combines isosurface and isocaps into one
F3 = [F1;F2+length(V1(:,1))];
V3 = [V1;V2];
% Visualization
P = patch('Vertices',V3,'Faces',F3,'FaceColor', ...
'cyan','EdgeColor','none');
view(3)
camlight
%Visualization
axis equal
stlwrite('G1-T05.stl',V3,F3)
Code 2:
% Clear all previous commands
clear all
close all
clc
figure(1)
% Variables you can change
Sizex = 1; %average length of RVE
Sizey = 1;
Sizez = 1;
Def = 60; %definition
% Variables you shouldn´t change
SFactx = (Sizex/2)/pi; %size factor of RVE
SFacty = (Sizey/2)/pi;
SFactz = (Sizez/2)/pi;
A = SFactx*pi; %lowest and max coordinates of meshgrid
B = SFacty*pi;
C = SFactz*pi;
Dx = A/Def;%definition factor
Dy = B/Def;
Dz = C/Def;
% Generation of gyroids
[X,Y,Z] = meshgrid(-A:Dx:A, -B:Dy:B, -C:Dz:C); %creates mesh grid
% Gyroid equation
OBJ =(A*B*C)-(cos(X/SFactx).* sin(Y/SFacty) + cos(Y/SFacty).* sin(Z/SFactz)...
+ cos(Z/SFactz).* sin(X/SFactx)+(0));
T = 0.5;
OBJ =(OBJ-T);
% Isosurface and isocap
[F1,V1] = isosurface(X,Y,Z,OBJ,0);
[F2,V2] = isocaps(X,Y,Z,OBJ,0,'below');
%Combines isosurface and isocaps into one
F3 = [F1;F2+length(V1(:,1))];
V3 = [V1;V2];
% Visualization
P = patch('Vertices',V3,'Faces',F3,'FaceColor', ...
'magenta','EdgeColor','none');
view(3)
camlight
%Visualization
axis equal
stlwrite('G1-T06.stl',V3,F3)
%How do I solve this problem?
Thanks
0 个评论
回答(1 个)
Varun
2023-5-17
Hello!
I tried to run the code on my end and after removing the “clear” statements from Code 2, the code ran perfectly! I am assuming that you used “stlwrite” from this File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-write-ascii-or-binary-stl-files . The output I obtained was:
To concatenate the two .stl files generated, you may make use of Microsoft’s 3D Builder or other similar applications. Hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Volume Visualization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!