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!
  1 件のコメント
Lovett
Lovett 2023 年 5 月 17 日
Thank you so much

サインインしてコメントする。


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 Center および File ExchangeVolume Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by