Code covered by the BSD License  

Highlights from
Circuit Analysis Toolbox

Circuit Analysis Toolbox

by

 

The circuit analysis toolbox allows you to perform an AC analysis of a circuit.

[nodeList,refNodeNew]=node_list(cirDesc,refNode)
function [nodeList,refNodeNew]=node_list(cirDesc,refNode)
% Creates a unique list of nodes and can redefine the reference node
% The "cirDesc" parameter is expected to be a single cell array containing:
%       component types
%       component designators
%       "from" nodes
%       "to" nodes
%       component values
%       component positive tolerances
%       component negative tolerances
%       control branches (of dependent sources)
%
% The "refNode" is a string containing the node to be used as the reference
% (or ground) node
% 
% The "nodeList" is a list of all the (unique) nodes found in the "cirDesc"
% parameter along with attribute "Accessible" describing whether the node
% has sufficient access allowing it to be measured in a physical circuit
%
% If only the "nodeList" is asked for in the output, the UITABLE is not
% opened for editing.
%
% Example:
%         [nodeList,refNodeNew]=node_list(cirDesc,refNode)
%         nodeList=node_list(cirDesc,refNode)

% Author: John McDermid
% Created: October 1, 2009

% Create a list of unique node names rom the "from node" and "to node"
% columns in the circuit description file
uniqueNodes=unique([cirDesc(:,3)' cirDesc(:,4)']);
N=numel(uniqueNodes);
if N<1
    error('Circuit file must not be empty!');
end
nodeList{N,3}=0;        % Pre-initialize for speed
    for I=1:N
        nodeList{I,1}=uniqueNodes{I};
        nodeList{I,2}=strcmp(uniqueNodes{I},refNode);
        nodeList{I,3}=true;  % Default assumes all nodes accessible
    end

% If only the "nodeList" is asked for in the output the uitable is not 
% opened for editing
if nargout~=1
% Create a "uitable" to display and edit the unique nodes and their
% attributes
colNames={'Node|Name' 'Reference|Node' 'Accessible'};
colFormat={'char' 'logical' 'logical'};
colEditable=[false true true];
nodeTableHandle=figure('Position',[560 528 228 300],...
                       'MenuBar','none',...
                       'NumberTitle','off',...
                       'Name','Edit Nodal Access');
uitable(nodeTableHandle, ...
    'Data',nodeList, ...
    'ColumnName', colNames, ...
    'ColumnFormat', colFormat, ...
    'ColumnEditable', colEditable, ...
    'RowName',[], ...
    'Position',[0 0 228 300], ...
    'CellEditCallback',@edit_callback);

% Define the close request function
set(nodeTableHandle,'CloseRequestFcn',@my_close_request);

% Wait for the "uitable" (and associated figure) to close and then return the
% selected reference node from the node list created by the "uitable"
waitfor(nodeTableHandle);
refNodeNew=nodeList{[nodeList{:,2}],1};
else
    refNodeNew=refNode;
end

function edit_callback(hObject,eventData)
% Subfunction to make "radio" selection for reference node in the uitable
if eventData.Indices(2)==2
    selectionIndex=eventData.Indices(1);
    table=get(hObject,'Data');
    column=[table{:,2}];
    column(:)=false;
    column(selectionIndex)=true;
    for I=1:numel(column)
        table{I,2}=column(I);
    end
    set(hObject,'Data',table);
end

function my_close_request(hObject,~)
% Subfunction to close the figure and assign the new node list 
% in the callers workspace
uiTableHandle=get(hObject,'Children');
list=get(uiTableHandle,'Data');
assignin('caller','nodeList',list);
snapnow
delete(gcbf)

Contact us