File Exchange

image thumbnail

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

version (8.24 KB) by Paul Wagner
Loads .raw simulation files created with LTspice (a free circuit simulation tool).


Updated 26 Apr 2009

View License

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.

Cite As

Paul Wagner (2020). Fast Import of Compressed Binary .RAW Files Created with LTspice Circuit Simulator (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (46)

I just tried this with LTSTPICE XVII and get the following error shown below. Is there and updated version somewhere else that I should be using?

>> RAW_DATA = LTspice2Matlab('RC.raw');
Error using LTspice2Matlab (line 205)
Format error in LTspice file "C:\Users\e212010\Desktop\B-2\SPICE\RC.raw" ... Bad tag name found

I extended the original version a couple years back to handle also DC Sweep (.dc), Operating Point (.op), Transfer Function (.tf), FFT (.four), Noise (.noise), and stepped simulations in addition to Transient Analysis (.tran) and AC Analysis (.ac) simulations. I recently added support for LTspice XVII files as well, and now put up my modified version on GitHub if anyone's interested:
I dropped support for MATLAB versions prior to 2016b in the meantime, but it should be possible to restore support for earlier versions with a few minor modifications only.


First of all thanks a lot for this very useful function. Concerning the LTspiceXVII support, I can provide some help here. As Michael Kincel (12 Apr 2017) and Jens Schönherr (2 Nov 2018) pointed out correctly, the additional argument for 'fopen' solves the problem for Matlab. However, if you are using Octave, you require some additional adjustments. I applied the necessary changes and added the function to one of my repositories. You can find the file at

Some hints for LTspice XVII (version Oct 23 2018 09:21:08 US Pacific):
If raw-file is saved in ASCII-mode then LTSPICE2MATLAB works as it is.
If raw-file is saved in binary-mode (default, w/ or w/o compression) then the changes described below by Michael Kincel (12 Apr 2017) are needed.

Since this function is helpfull I suggest to update LTSPICE2MATLAB.

Ha, I'm a goober. Was stuck in old habits and tried to feed the script an ASCII file. Thanks for the great tool!

Great, useful script. Thanks to the mod by @Michael Kincel, I could make it work perfectly.

alli sita

in which case this error message:'Format error in LTspice file "%s" ... End of file unexpectedly encountered' will appear? What does it mean? I'm trying to understand it in the programm but I can't?

alli sita

Could somebody help me please? I'm losing my mind
Is the syntax to execute ltspice XVII with matlab true?
!XVIIx64.exe -b -r
I find info nowhere

alli sita

alli sita

thank you for your help @Michael Kincel

alli sita

alli sita

thanks you this is a good tool that you have created!!! it helps me a lot
I would have to ask a question to you and anybody who will read this comment: Did you use ltspice in an optimization process?
I ask this question because I work on electrical machine modeling. It is modelling the machine using equivalent magnetic circuit (which looks like electric circuit with resistor and source). I am then using ltspice coupled with matlab to solve this circuit.I create my netlist using matlab, I solve using ltspice, I collect the results from .raw files using a matlab program and I process the results using also matlab. It works until now. I am doing optimization so I need to run over and over again ltspice until the algorithm find the optimal point. I want to know if this process of running of multiple time (through optimisation or "for loop") is suitable for ltspice? I found that it can give me false results or doesn't comptute the results at certains time (I obtain NaN (Not an Number) values). Your feedbacks will be very appreciated.


This is great, however, to recover the netlist names you need to load the whole file into memory which can be prohibitive with large files. I would suggest that a function option that only drops the netlist names into a structure would be essential to this library. Why? because if you ever make a change to the file then the order changes and you have to re load the file, check the names and then generate a vector that can select only the netlists that are wanted.

Another option would be to be able to select only the data that you want by name like this:
netlistdata= LTspice2Matlab('thisistherawfile.raw','V(U1:3)');
netlistdata= LTspice2Matlab('thisistherawfile.raw',['V(U1:3)' 'I(U3:2)' 'I(R2)']);

@Michale; Works great for me with your changes! Thanks for the fix!

Harsha M V

Hans Peter

@Michael; it doesnt Work for me: i still get an Error:
"Error using LTspice2Matlab (line 186)
Format error in LTspice file <filepath>"

Regarding the error with LTSpice XVII, as Joshua Jones pointed out, the error is due to the new version of LTspice using UTF16 encoding for .RAW files.

The simple fix for this is to update lines 153 and 156 of the code to the following:
153 - fid = fopen(filename, 'rb', 'n', 'UTF16LE');
156 - fid = fopen(sprintf( '%s.raw', filename ), 'rb', 'n', 'UTF16LE');

Matlab will give a warning because it doesn't recognize the encoding scheme, but everything imports as before.
Hope this helps.

Fails to work for LTspice XVII.

It fails to work for LTspice XVII. I hope the next version will fix this problem.



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.


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?

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);

Hu Liu

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.

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


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



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.

Dick Benson

Sweet! Thanks!

Raj Sodhi

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.



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




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.



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


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


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


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.



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.

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.


Updated help section at beginning of file

Added support for AC Analysis (.ac) simulations

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

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux