ltspice2matlab icon indicating copy to clipboard operation
ltspice2matlab copied to clipboard

Unable to load .raw data with spice list directive

Open ethangoldstein opened this issue 3 years ago • 3 comments

Hello,

I am able to load the .raw file when I run a basic .tran command. However, when I include a .step directive in the simulation I get the following error from MATLAB:

Error using reshape Size arguments must be real integers.

Error in LTspice2Matlab (line 531) raw_data.variable_mat = reshape(raw_data.variable_mat, mat_size(1), mat_size(2) / num_steps, num_steps);

Error in test (line 6) sr = LTspice2Matlab(path);

Any help would be greatley appreciated.

Thank You,

Ethan

ethangoldstein avatar Mar 10 '21 19:03 ethangoldstein

I got the same error. Attached is an example file that comes with LTspiceXVII that can reproduce this error.

C:\Program Files\LTspiceXVII\examples\Educational\FRA\Eg1.asc Run simulation -> Eg1.raw

".tran 0 {5/Freq+.1m} .1m" in Eg1.asc can save computation burden significently, but it cause the simulation data points (and also the matrix size) vary depends the variable {Freq} along each step.

(line 531) "mat_size(2) / num_steps" is not compatible with this situation and causes the error.

I would appreciate taking consider this situation. Thank you.

YC Niu Eg1.zip

yc-niu avatar Dec 08 '21 16:12 yc-niu

@ethangoldstein @yc-niu

I also had this problem recently, but finally solved it perfectly.

I guess the reason is because the length of the data is inconsistent, since LTSpice is a solver with variable step size.

The solution is to use the software "ltsputil.exe" to interpolate the data in the raw file to achieve a consistent step size. For the new version of LTSpice, you also need to use "ltsputil17raw4.exe" to convert raw files.

The above software can be easily found in google. Below is the code I use, just for reference:

cd/d D:\Circuit_results\sweep_new\verify ltsputil17raw4.exe fixed_frequency.raw converted_fixed_frequency.raw ltsputil.exe -eo converted_fixed_frequency.raw output_fixed_frequency.raw 40000

Note that they should run by CMD command, or use the batch file.

kunkun9527 avatar May 31 '22 08:05 kunkun9527

One more important step is to keep raw uncompressed, the following command can be used in LTSpice.

.opt plotwinsize=0

But this will greatly increase the raw file size.

kunkun9527 avatar May 31 '22 08:05 kunkun9527