View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.6 | 47 ratings Rate this file 86 Downloads (last 30 days) File Size: 120 KB File ID: #3642 Version: 1.0
image thumbnail



Don Riley (view profile)


23 Jun 2003 (Updated )

3D CAD data to MATLAB Converter, CAD STL to MATLAB Patch.

| Watch this File

File Information

CAD2MATDEMO is a demonstration of importing 3D CAD data into MATLAB.

The demo includes:

1) the general program,
2) 4 CAD data file samples, and
3) a simple script that executes the program to show the 4 samples.

To get CAD data into MATLAB, the process is:

1) Export the 3D CAD data as an ASCII STL (or Pro/E render SLP) file.
2) This MATLAB routine reads the CAD data, and
3) Once read, the CAD data is rotated around a bit for viewing.

The program has been tested with: AutoCAD, Cadkey, and Pro/Engineer.
It should work with most any CAD programs that can export STL files.

Format Details: STL is supported, and the color version of STL that Pro/E exports, called 'render' is also supported. The render (SLP) is just like STL but includes color.

Only that data associated with STL or SLP files are translated, e.g., geometry and the geometry color. No textures, transparencies, or other such things are exported with the STL (or SLP) file.

Note: This routine has both the import function and some basic manipulation for testing. The actual reading mechanism is located at the end of the demo file.


This file inspired 3 D Puma Robot Demo, X Mas Tree, 【Light Version 】Matlab Stl Gui Slice Program Yong Da, and Robotic Arm Simulator.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (56)
11 Feb 2017 iwan gunawan

07 Feb 2017 mahmood jashnemaryam

29 Dec 2016 Yiwu Fang


22 Nov 2016 saleh

saleh (view profile)


27 Oct 2016 behdad

behdad (view profile)

21 Sep 2016 hurd cheng

very good

Comment only
30 Jun 2016 Harish Babu Kankanala

Was very helpful. Thank you.

30 Jun 2016 Harish Babu Kankanala

27 Jun 2016 Carlos Macedo

Looks fantastic! very useful

02 Jun 2016 Malikireddy

do we need any toolbox so that rndread() is understood by MATLAB?

Comment only
14 May 2016 Yong Da

Yong Da (view profile)

Fantastic code for me, thanks

18 Mar 2016 He Li

He Li (view profile)

Great job!! It is very help for us to import 3d model into matlab.

31 Dec 2015 Ali Jafari

24 Nov 2015 Roopam Dey

I am having error while the matrix multiplication:

for ang = 0:1:90
nv = rx(ang)*V;

please help

18 Dec 2014 Chen

Chen (view profile)

Nice job! Should I replace "AXIS" (Line 52)with "axis"?

05 Oct 2014 Vibhute

finaly I imported STL file with your work

24 Sep 2014 Charles Eloquin Leclerc

Work great but....why are you moving the object at the end of the script? For huge file on computer with High CPU / Low GPU it make the script x10 time longer.

Comment only
10 Jul 2014 Junjie

Junjie (view profile)

great work!

10 Feb 2014 Aurelio

Hello I am using MATLAB R2012b and run the script the image appears in 3D, but it does not set the variables of structure (S1, S2 ...), or the variables (V1, C1, N1) ... the workspace is blank, and no files. m is created. Please can someone help me? thank you

Comment only
02 Dec 2013 liguo

liguo (view profile)


Comment only
28 Aug 2013 Emmanuel Farhi

Thanks, I use it for reading STL files.

04 Jun 2013 Scott

Scott (view profile)


02 Jun 2013 Rooha Siddiqui

can you please help me with my problem ? I have a catia figure saved in . stl format and i want it to read in matlab . I m finding it difficult to find the function that does that

23 Apr 2013 Ali

Ali (view profile)

Hi, it is a nice job, please could you tell me how can I machining an stl file? Regards

24 Nov 2012 shiva

shiva (view profile)

A tip to automatically add a column of 1s to vertices matrix

add this line in the cad2mat function

s0.V0 = [V(:,1), V(:,2), V(:,3), ones(length(V),1)];


function cad2mat(filename)
filename = 'Link0.stl'; % part
% Read the CAD data file:
[F, V, C] = rndread(filename);
s0=struct('F0', F,'V0', V,'C0', C);
s0.V0 = [V(:,1), V(:,2), V(:,3), ones(length(V),1)];

03 Sep 2012 Carlos

Carlos (view profile)

30 Jun 2012 Soner Ulun


I have tried export a solid drawing, successfully I can see the drawing in matlab but I could not save it as mat-file. When I run the cat2matdemo It gives an error ;

Cannot find an exact (case-sensitive) match for

The closest match is: axis
in C:\Program

Error in cad2matdemo (line 53)
AXIS([-vsize vsize -vsize vsize -vsize vsize]);

Can you please help me with the subject. I have tried R2011B and R2012a versions.

Comment only
04 May 2012 erikmarte

nice and awesome jobe man i just can say that you are great but, im stuck, i think i have a problem with this, because when i try to load a stl file it apears on the command windows ??? indefined function or variable "v" Error in cad2matdemo>rndread at 223 vout = v';.
i will be glad if you can give me a hand on it

Comment only
05 May 2011 Joachim

08 Apr 2011 YT

YT (view profile)

very good tools!thank you

10 Mar 2011 Jeroen Vandersteen

02 Mar 2011 William LaCava

A note to SolidWorks users: be sure to export your STL files as ASCII, not binary. To do this for a solid part, hit 'saveas', choose *.stl, and go into Options. In my case, solidworks defaulted to export in binary.

22 Jun 2009 badr Higab

04 Apr 2009 Alex Frid

i have tried to load a different 6DOF arm in to the code and bumped on problem of the initial location. How do you set what the initial location of each part before you performing the InitHome function call.

Comment only
12 Mar 2009 Husam Aldahiyat

22 Aug 2008 Greg C

Any suggestions on the memory pre-allocation? I made several attempts unsuccesfully.

24 Jul 2008 Sharina S

Great work indeed.This helped me in my project.

27 Mar 2008 igor scardanzan

what one needs to start exporting matlab patch in CDF pre processing tools
just slow in writing the STL file

09 Mar 2008 Scott Burnside

After adding some preallocation I found this code to be very simple, straightforward and robust. This example is particularly useful to me as I am writing a 3D track display and was able to write a process based on your example so that we could develop our track symbols in autocad and bring the vertices and faces into Matlab as a patch object. An amazing combination of tools. Thank you for sharing.

12 Oct 2007 M Genest

Great tool

I strongly recommend you modify the file opening function to pre-allocate the memmory. This allow to open large model a lot faster.

This can easily be done

Comment only
09 Oct 2007 Raphael Beckers

Exactly what I was searching for. A little bit slow, yes, but I have no Idea how to make it faster.

05 Jun 2007 Roland Lehmann

Great program that saved me a lot of time. Thank you for sharing!

27 Jan 2007 abelmi ab

Look great

23 Jan 2007 Matt Donath

Good demo for small models. However, it took 20 minutes to load a model of a transport vehicle.

15 Jan 2007 Ha Seungwon

it's very good.

13 Dec 2006 Sebastian Held

great demo; easy to use. Thanks.

26 Aug 2006 SIVA PRASAD


11 Jul 2006 N Q

Works first time. Very useful, but slow for big models.

06 May 2006 H O

30 Mar 2006 S G

Very nicely done

16 Mar 2006 abelmi ab

I had tried it.It's work good.Nice job

17 Feb 2005 Tom Mansfield

This has helped me so munch. Thanks.

19 Dec 2004 Chris Barnhart

Works great!

10 Nov 2004 Fadi Glor

works great - do you have anything for performing boolean operations on stl-files? Like merging two stl-files into one? Looking for the intersection of two stl-files?

12 Feb 2004 Rajeev Jain

20 Oct 2003 Duane Nightingale

Very nice utility that seems to be working for us right out of the box. Thanks for sharing.

Contact us