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

PSpice60(netlist, time, path)
function data = PSpice60(netlist, time, path)

% set default path
if nargin < 3, path = '\MPS'; end

% check time frame
time = time .* 1e3;
if time(1) == 0
    time = [                 '1p ' num2str(time(2)) 'ms'];
else
    time = [num2str(time(1)) 'ms ' num2str(time(2)) 'ms'];
end

% open and start cir-file
fid = fopen([path '\TEMP\TEMP.CIR'], 'wb');
fwrite(fid, ['* matlab circuit *' char(13) char(10)], 'char');

% writing netlist to file
for i = 1:length(netlist)
    fwrite(fid, [netlist{i} char(13) char(10)], 'char');
end

% writing final commands and close file
fwrite(fid, ['.TRAN ' time char(13) char(10)], 'char');
% this defines the output parameters you want back from PSpice
% in my case the voltage V betwwen the node out and ground
fwrite(fid, ['.PROBE V(0,out)' char(13) char(10)], 'char');
fwrite(fid, ['.END' char(13) char(10)], 'char');
fid = fclose(fid);

% run PSpice6.0
oldpath = chdir([path '\PSpice60\']);
[x output] = dos([path '\PSpice60\PSEXEC.EXE ' path '\TEMP\TEMP.CIR', '-echo']);
delete *.tmp
delete ..\TEMP\*.tmp
chdir(oldpath);
if x
    fid = fopen([path '\TEMP\TEMP.OUT']);
    text = fread(fid, '*char')';
    fid = fclose(fid);
    text(text == char(10)) = [];
    error(text); 
end

% import simulation results
data = readdat([path '\TEMP\TEMP.DAT']);

Contact us at files@mathworks.com