Simulink Subsystem False Results
이전 댓글 표시
The script isnt the project but rather a simple code for the sake of the doubt. This Script should be used to design a Mask that changes the number of blocks (Gain blocks) depending on the input value given from the user. The script should only construct an Input port (R) and multiple of Gain blocks which will all be connected automatically together. This script is inserted under "Mask Editor -> Code" as Gain(gcb)
Problem:
1- The Gain blocks are not generated, rather series of lines named Gain. (see picture)

2- How to assign gain value for all the Gain blocks (should be entered by the user in the Mask)
The Code:
function Gain(sys)
N = max([1 round(str2double(get_param(sys,'N')))]);
% clear out any old, unneeded circuitry
lines = find_system(sys,'SearchDepth','1','LookUnderMasks','On','FindAll','On','Type','Line');
delete(lines);
blks = find_system(sys,'SearchDepth','1','LookUnderMasks','On','BlockType','Gain');
delete_block(blks);
% change in position between blocks
blockIncrement = [40 0];
% calculate all of the required block positions
blockPosition = zeros(N,4);
blockPosition(1,1:2) = [305 23];
blockPosition(1,3:4) = blockPosition(1,1:2);
loopIncr = 1;
for ii = 2:loopIncr:size(blockPosition,1)
blockPosition(ii,1:2) = blockPosition(ii-1,[3 2])+blockIncrement;
blockPosition(ii,3:4) = blockPosition(ii,1:2);
end
% add the blocks
cblk = 1;
for ii = 1:loopIncr:size(blockPosition,1)
h = add_block('simulink/Math Operations/Gain',[sys '/Gain' num2str(cblk)],'Position',blockPosition(ii,:));
set(h,'NamePlacement','Alternate');
set_param(h,'K','N');
cblk = cblk+1;
end
% connect Connectors to Cable
add_line(sys,'R/1','Gain1/1','autorouting','on');
% connect Cable segments together
for ii = 2:loopIncr:size(blockPosition,1)
add_line(sys,['Gain' num2str(ii-1) '/1'],['Gain' num2str(ii) '/1'],'autorouting','on');
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!