Error using patch Value must be of numeric type and greater than 1.

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';
Unable to resolve the name '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

What are these commands supposed to do?
F12(0)
F23(0)
Are these parameters arrays or functions?
function [F]=F12(fi2)
F=[C12(fi2),[0 0 0]';
[0 0 0 1]];
%%
function [F]=F23(fi3)
F=[C23(fi3),[50 0 0]';
[0 0 0 1]];
%%
% trajektoria 1
fi1=[0:1:360];
fi2=30+20*sin(10*fi1*pi/180);
fi3=60*sin(20*fi1*pi/180+15*pi/180);
What are C12 and C23?
Please provide everything needed to run your code.
C23 is not defined in the file attached.
function [C]=C12(fi2)
C=[cos(fi2) -sin(fi2) 0;
0 0 -1;
sin(fi2) cos(fi2) 0];
function [C]=C23(fi3)
C=[cos(fi3) -sin(fi3) 0;
sin(fi3) cos(fi3) 0;
0 0 1];

Sign in to comment.

 Accepted Answer

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
Name Size Bytes Class Attributes C11 1x1 2448 struct C12 1x1 29352 struct C2 1x1 30960 struct C3 1x1 30960 struct ans 1x37 74 char cmdout 1x33 66 char
% [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

That's almost good.
any idea why the holes aren't round?
It looks squished :P
"any idea why the holes aren't round?"
The holes are round: look at the axes ranges.
If you want the axes ranges displayed with equal lengths for each unit then call
axis equal
That worked thanks. I'm quite new in matlab. I've other issue but that needs next ticket
Experiment with the lightangle arguments to get the result you want —
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')
.

Sign in to comment.

More Answers (0)

Products

Release

R2023b

Tags

Asked:

on 20 Jan 2024

Edited:

on 20 Jan 2024

Community Treasure Hunt

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

Start Hunting!