No BSD License  

Highlights from
Unit Conversion

image thumbnail

Unit Conversion

by

 

25 Mar 2003 (Updated )

MATLAB function, GUI & Simulink block for Unit Conversion.

unitopenfcn(UnitTypeIndex)
function unitopenfcn(UnitTypeIndex)
%unitopenfcn   Sets details for the Unit Conversion block

% Get the block
blk=gcb;

% Get Values
[f,o,s]=unittool(str2num(UnitTypeIndex));
if isempty(f), return; end;

% Set the name according to its type
% Find any blocks already of this type - e.g. 'Length Conversion2'
baseBlkName=[s{4} ' Conversion'];
sys=find_system(gcs,'SearchDepth',1,'RegExp','on','Name',[baseBlkName '\d*']); % with any integer or none
i=1;
vSuffix=[{''},num2cell(1:length(sys))];
while strmatch([gcs '/' baseBlkName int2str(vSuffix{i})],sys,'exact'),
   i=i+1;
end
if i==1, chSfx=''; else, chSfx=int2str(i-1); end;

% Apply the parameters to the block
set_param(blk,'Factor',num2str(f,8),'Offset',num2str(o,8),...
   'UnitTypeIndex',mat2str(s{1}),'InputText',s{2},'OutputText',s{3},...
   'Name',[baseBlkName chSfx]);

Contact us