Error while concatenating two .stl files

조회 수: 6 (최근 30일)
Lovett
Lovett 2023년 5월 10일
답변: DGM 2025년 7월 17일
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

답변 (2개)

Varun
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!

DGM
DGM 2025년 7월 17일
To combine STL files, triangulation objects, or sets of F,V data, see this example:
FWIW, it's not necessary to use FEX #20922 in modern versions. You already have an STL encoder stlwrite, and #20922 will cause a name conflict unless you rename it. They're not the same function, and they don't behave the same.

카테고리

Help CenterFile Exchange에서 Volume Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by