ListOfDevices Function: Sample Code for Matlab®

 

Sample Code

%A list of branches is desired, without using any filter

DeviceType = 'Branch';

FilterName = '';

%Execute the ListOfDevices command

Output = SimAuto.ListOfDevices(DeviceType,FilterName);

%If the first cell in SimAutoOutput ~= '', then that means an error

%occurred.

if ~(strcmp(SimAutoOutput{1},''))

disp(SimAutoOutput{1}) 

else

%Otherwise, no errors. Display the branch information. 

disp('ListOfDevices successful') 

 

%Devicelist1 contains the From: bus number 

%Devicelist2 contains the To: bus number 

%Devicelist3 contains the Bus identifier 

devicelist1 = double(transpose(SimAutoOutput{2}{1})); 

devicelist2 = double(transpose(SimAutoOutput{2}{2})); 

devicelist3 = SimAutoOutput{2}{3}; 

 

%If the device list is greater than 25, don't bother attempting to 

%display it on the screen. 

if (size(devicelist1,1) > 25)  

disp('Device list exceeds 25; use ''devicelist'' to manage list of devices') 

else  

%Otherwise, display the branches' information. 

disp(DeviceType) 

disp('From/To/Identifier') 

for counter = 1:size(devicelist1,1) 

%num2str converts the numbers within devicelist1 and 

%devicelist2 to strings for output with disp(). the char() 

%function is called on devicelist3's members because the 

%SimAuto object returns a character array (as opposed to a 

%properly Matlab-format string) and this array must be 

%converted to a Matlab-format string. 

disp([num2str(devicelist1(counter)) ' ' ... 

num2str(devicelist2(counter)) ' ' ... 

char(devicelist3(counter))])  

end 

end 

end