Error using patch Value must be of numeric type and greater than 1.
8 views (last 30 days)
Show older comments
Hi, i need to figure some stl files and it's giving me an error
Error using patch
Value must be of numeric type and greater than 1.
Error in rysujPATCH (line 63)
czlon11=patch('Faces',C11.Faces,'Vertices',C11.Vertices,'FaceColor',C11.FaceColor);
matrixes are included
this is the code
%%
% Rysuj czlony
P2=C2.Vertices';
P3=C3.Vertices';
% ustawianie czlonow
P2=F12(0)*[P2; ones(1, size(P2, 2))];
%
C2R=C2;
%
C2R.Vertices=P2(1:3,1:size(P2, 2))';
%
P3=F12(0)*F23(0)*[P3;ones(1,size(P3, 2))];
%
C3R=C3;
C3R.Vertices=P3(1:3,1:size(P3, 2))';
%% rysowanie
figure(1);
axis([-100,400,-100,400,-100,700]);
grid on;
hold on;
%
czlon11=patch('Faces',C11.Faces,'Vertices',C11.Vertices,'FaceColor',C11.FaceColor);
%%
%czlon12=patch(C12);
czlon12=patch('Faces',C12.Faces,'Vertices',C12.Vertices,'FaceColor',C12.FaceColor);
%
%czlon2=patch(C2R);
czlon2=patch('Faces',C2R.Faces,'Vertices',C2R.Vertices,'FaceColor',C2.FaceColor);
%
%czlon3=patch(C3R);
czlon3=patch('Faces',C3R.Faces,'Vertices',C3R.Vertices,'FaceColor',C3.FaceColor);
clear P2 P3 C2R C3R
I've already add +1 to whole faces matrix and still no luck.
Please help
EDIT: I've exported the stl files from SOLIDWORKS 2024
6 Comments
Accepted Answer
Star Strider
on 20 Jan 2024
Edited: Star Strider
on 20 Jan 2024
I was not able to get these to work with patch (I still do not understand what that problem is), however with a minor modification, I was able to get them to work with the trisurf function —
load('matrixes.mat')
whos
% [vl,vu] = bounds(C11.Vertices)
% [r,c] = size(C11.Faces)
% [vl,vu] = bounds(C12.Vertices)
% [r,c] = size(C12.Faces)
% [vl,vu] = bounds(C2.Vertices)
% [r,c] = size(C2.Faces)
% [vl,vu] = bounds(C3.Vertices)
% [r,c] = size(C3.Faces)
figure
trisurf(C11.Vertices-1, C11.Faces(:,1), C11.Faces(:,2), C11.Faces(:,3), 'FaceColor',C11.FaceColor)%, 'EdgeColor',C11.FaceColor)
title('C11')
figure
trisurf(C12.Vertices-1, C12.Faces(:,1), C12.Faces(:,2), C12.Faces(:,3), 'FaceColor',C12.FaceColor)%, 'EdgeColor',C12.FaceColor)
title('C12')
figure
trisurf(C2.Vertices-1, C2.Faces(:,1), C2.Faces(:,2), C2.Faces(:,3), 'FaceColor',C2.FaceColor)%, 'EdgeColor',C2.FaceColor)
title('C2')
figure
trisurf(C3.Vertices-1, C3.Faces(:,1), C3.Faces(:,2), C3.Faces(:,3), 'FaceColor',C3.FaceColor)%, 'EdgeColor',C3.FaceColor)
title('C3')
EDIT — (20 Jan 2024 at 15:16)
Experimenting with the surface lighting —
figure
trisurf(C11.Vertices-1, C11.Faces(:,1), C11.Faces(:,2), C11.Faces(:,3), 'FaceColor',C11.FaceColor, 'EdgeColor','none')
lightangle(-45, 25)
lighting('flat')
title('C11')
figure
trisurf(C12.Vertices-1, C12.Faces(:,1), C12.Faces(:,2), C12.Faces(:,3), 'FaceColor',C12.FaceColor, 'EdgeColor','none')
lightangle(-45, 25)
lighting('flat')
title('C12')
figure
trisurf(C2.Vertices-1, C2.Faces(:,1), C2.Faces(:,2), C2.Faces(:,3), 'FaceColor',C2.FaceColor, 'EdgeColor','none')
lightangle(45, 65)
lighting('flat')
title('C2')
figure
trisurf(C3.Vertices-1, C3.Faces(:,1), C3.Faces(:,2), C3.Faces(:,3), 'FaceColor',C3.FaceColor, 'EdgeColor','none')
lightangle(45, 65)
lighting('flat')
title('C3')
.
4 Comments
Star Strider
on 20 Jan 2024
load('matrixes.mat');
figure
trisurf(C11.Vertices-1, C11.Faces(:,1), C11.Faces(:,2), C11.Faces(:,3), 'FaceColor',C11.FaceColor, 'EdgeColor','none')
hold on
trisurf(C12.Vertices-1, C12.Faces(:,1), C12.Faces(:,2), C12.Faces(:,3), 'FaceColor',C12.FaceColor, 'EdgeColor','none')
trisurf(C2.Vertices-1, C2.Faces(:,1), C2.Faces(:,2), C2.Faces(:,3), 'FaceColor',C2.FaceColor, 'EdgeColor','none')
trisurf(C3.Vertices-1, C3.Faces(:,1), C3.Faces(:,2), C3.Faces(:,3), 'FaceColor',C3.FaceColor, 'EdgeColor','none')
lightangle(45, 65)
lighting('flat')
% material('metal')
hold off
axis('equal')
view(-45, 20)
Ax = gca;
Ax.Visible = 0;
sgtitle('Assembled Segments')
.
More Answers (0)
See Also
Categories
Find more on Develop uifigure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!