Code covered by the BSD License  

Highlights from
Matlab <-> PSpice Interface

image thumbnail
from Matlab <-> PSpice Interface by Frank Sommerhage
How to call PSpice from Matlab and import the results

writepwl(file, time, data, t, d)
% writes a pwl-file for PSpice
%
% file : filename for data
% time : time
% data : data
% t    : time format, e.g. 'us' (s) or 'ms' ...
% d    : data format, e.g. 'm', 'u', or 'n' ...

function writepwl(file, time, data, t, d)
fid = fopen(file, 'w');
% write a backet '(' - PSpice wants it
fwrite(fid, '(', 'char');
% write five pairs of time and data in one line, start next line and write
% a plus '+' sign. fprintf continues until time and data are 'empty'
fprintf(fid, ['%0.4f' t ' %0.4f' d ...
             ' %0.4f' t ' %0.4f' d ...
             ' %0.4f' t ' %0.4f' d ...
             ' %0.4f' t ' %0.4f' d ...
             ' %0.4f' t ' %0.4f' d ...
             '\r\n+ '], [time'; data']);
% go four steps back in the file (that's where the carriage return '\r' is)
fseek(fid, -4, 0);
% overwrite the '\r\n' with a closing bracket ')' - PSpice needs it
fwrite(fid,  [d ')   '], 'char');
fid = fclose(fid);

Contact us at files@mathworks.com