View License

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

» Watch video

Highlights from
Fast Import of Compressed Binary .RAW Files Created with LTspice Circuit Simulator

4.5 | 17 ratings Rate this file 41 Downloads (last 30 days) File Size: 8.24 KB File ID: #23394 Version: 1.3
image thumbnail

Fast Import of Compressed Binary .RAW Files Created with LTspice Circuit Simulator


Paul Wagner (view profile)


22 Mar 2009 (Updated )

Loads .raw simulation files created with LTspice (a free circuit simulation tool).

| Watch this File

File Information

LTSPICE2MATLAB imports an LTspice IV .RAW waveform file containing data from a Transient Analysis (.tran) or AC Analysis (.ac) simulation, and converts voltages and currents vs. time (or frequency) into a Matlab data structure. This function can read compressed binary, uncompressed binary, and ASCII file formats. In the case of compressed binary, the data is automatically uncompressed using fast quadratic point insertion. This function handles very large binary simulation files efficiently, and has an option to load only a subset of a file's waveforms to reduce memory consumption. Type >> help LTspice2Matlab for details.

Use LTSPICE2MATLAB to import LTspice waveforms for additional analysis in Matlab, or for comparison with measured data. LTspice2Matlab has been tested with LTspice IV version 4.01p, and Matlab versions 6.1 and 7.5., and regression testing has been used to expose the function to a wide range of LTspice settings.

Note: LTspice IV is a Spice III simulator and schematic capture tool freely avaliable for download at It is optimized for simulation of switching regulators, but can simulate many other types of circuits as well and comes with a variety of component models.


This file inspired Run Ngspice Simulation And Import Rawfile.

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (24)
13 Jan 2017 Mathieu

13 Jan 2017 Mathieu

03 Jan 2017 Joshua Jones

This file would have been a life saver for me, however, using R2016b and LTspice XVII, this M-file did not work. After some messing around, I found out that the use of fgetl() was causing problems, because the .RAW file is encoded in UTF-16. Encoding the .RAW file fixed this, but the rest of the importing of the data failed. I think this code could probably do with some revision and updating.

Comment only
12 Nov 2016 Al

Al (view profile)

Matlab would not run this with Dropbox running. Needed to restart computer and turn off Dropbox. Once it is running in 2015a, the data does not make sense. It tells me there are 43991 rows of data when there are 19712 when I export the data manually. The time vector is a row of what appears to be a value from each column of variable. Definitively not the time vector. The raw data variable matrix appears to be jumbled. Does anyone know how to fix this?

Comment only
09 Sep 2016 Michael Du

The LTSpiceIV version I used is 4.23I and Matlab is 2015a. One need is to study the Vx struct to find out where the variables are and then pull the data separately.

Vx = LTspice2Matlab( filename );
Vx_name = Vx.variable_name_list;
freq = Vx.freq_vect;
for k=1:km
Vsig(k) = Vx.variable_mat(N,k);

18 May 2016 Georges-Andre Chaudron


17 May 2016 Hu Liu

Hu Liu (view profile)

10 May 2016 Nico Leverkus

This function is awesome! It really helped me a lot.
First I was a little overstrained my the amount of the imported Data, but since I'm using labels in LTspice everything is fine.

10 May 2016 alli sita

hello everybody,
forgive my english, this is not my first langage. i am using this program but I still have the error message

C:\Users\Sita.2015-4-A\Google Drive\quart_machine\RdR_DSPM\DSPM.raw
AccŠs refus‚.
Error using LTspice2Matlab (line 158)
Could not open file "DSPM.raw"

Error in DSPM_MCL (line 25)

Error in Main (line 3)

what can I do to solve this problem

Comment only
13 Apr 2016 bakr bagaber

26 Jul 2015 Sidney

Sidney (view profile)

I am trying to run the LTSpice2Matlab code provided here but I am getting this error

>> LTspice2Matlab
Error using LTspice2Matlab (line 130)
LTspice2Matlab takes 1, 2, or 3 input parameters. Type "help LTspice2Matlab" for details

Please can someone advice me on how to solve this problem?

Kind regards


23 Dec 2013 Raptrick

Hi Paul this is very usefull. Thanks! I often work with parameter stepping. I observed that LTspice2matlab does not cover this feature. It outputs all steps sequencially without notifying that it is stepped data and providing info about about runs. This would a be nice feature for the next version.

29 Jun 2013 Dick Benson

Dick Benson (view profile)

Sweet! Thanks!

13 May 2013 Raj Sodhi

Raj Sodhi (view profile)

This is fantastic! I struggled with Helmut's ltsputil.exe program for a while, intending to bring the final results into Matlab and this program does all that in 1 step.

11 Feb 2013 Richard

06 Nov 2012 Alan

Alan (view profile)

This failed for me

Error using LTspice2Matlab (line 212)
Format error in LTspice file "/Users/acurtis/Desktop/test.raw" ... Wrong number of
columns in the variable define section

I created the raw file from an example circuit netlist I got from

I chose the "RC filter AC response" and copied the netlist to a file. I ran ngspice with the command

ngspice --batch --rawfile="test.raw" ""

and then in MATLAB


Comment only
21 May 2012 Daniel

Daniel (view profile)


Very useful function. However, i detect some "NaN" (not a number) conversions in MATLAB which are not a problem to plot data but it is for making calculations. Does anybody know how to deal with them without increasing the computation time.

Comment only
18 Dec 2011 sergi

sergi (view profile)

09 Mar 2011 Mickael Lefebvre


Thanks very much for this function, I managed to get it to work with Octave (3.2.0 on Win7). Are you interested in the modifications?
Thanks again

20 Apr 2009 Lian

Lian (view profile)

Hello, anybody can upload or post the commands in matlab to plot the "RAW DATA" structure into a Figure, thank you in advance.

Comment only
20 Apr 2009 Lian

Lian (view profile)

this file is very useful as the analysis function in LTspice is limited in some extend.

20 Apr 2009 Howard

Howard (view profile)

Update, my previous comment was caused by an error I made when using LTspice2Matlab.m Once I enclosed the path and file name in single quotes the LTspice2Matlab.m file program ran successfully. I had forgotten strings have to be enclosed in single quotes in Matlab.


11 Apr 2009 Howard

Howard (view profile)

I have tried using LTspice2Matlab.m with the 1010.asc and pll2.asc examples that come with LTspice and both produce an "unexpected Matlab operator error. This is with version 4.01p of Ltspice and versions 7.5 and 7.7 of Matlab. I also noticed Matlab's Current Directory function doesn't work with LTspice2Matlab.m

I assume others have had better results but so far I have been unable to load a raw LTspice file.

Comment only
23 Mar 2009 Heinrich Acker

Thanks alot for this file. It works as expected, much better than my own import function, which requires to set LTspice to ASCII output. But ASCII is not the preferred output, one usually wants to use LTspice with its .RAW format.

The source of this function uses long, descriptive varnames and has a very good help section at the beginning.

Btw, I tested with Matlab 7.5 (R2007b) and LTspice III (2.16z), and everything worked well.

It may sound pedantic, but there are only few comments after the help section and mlint gives quite some warnings on this file.

It would be nice to see this very useful program extented to other simulation types than .TRAN.

28 Mar 2009 1.1

Added support for AC Analysis (.ac) simulation files.

30 Mar 2009 1.2

Added support for AC Analysis (.ac) simulations

26 Apr 2009 1.3

Updated help section at beginning of file

Contact us