フィルターのクリア

How to change position of duplicated Simulink module in GUI dynamically?

2 ビュー (過去 30 日間)
Saeed Soltani
Saeed Soltani 2016 年 2 月 11 日
コメント済み: Fangjun Jiang 2016 年 2 月 11 日
Hi,
I have created a simple GUI in which by clicking a pushbutton, it duplicates (using add_block) an existing module. The problem is that, it creates the new module in the same position each time, therefore by double clicking the last created one may not be recognized in the first look. I would like to optimize it by changing the position (for ex: a bit forwarding) dynamically by each clicking. Thanks in advance.
Best regards,
Saeed

採用された回答

Fangjun Jiang
Fangjun Jiang 2016 年 2 月 11 日
編集済み: Fangjun Jiang 2016 年 2 月 11 日
Assume you are duplicating a block in a model using add_block (but not add_block() from a library source), the new block name will always be suffixed with a number starting from 1 and it is available.
sb='untitled/Gain';
hBlock = add_block(sb, sb, 'MakeNameUnique', 'on');
NewName=get(hBlock,'Name');
Offset=regexp(NewName,'\d+','match');
Offset=Offset{end};
Position=get(hBlock,'Position');
set(hBlock,'Position',Position+10*str2double(Offset));
If the source block name starts as e.g. 'untitled/Ga123in5', it should also work. I don't think you care how much is the offset as long as it distinguish from other blocks. Make the linear scale larger could also help.
  2 件のコメント
Saeed Soltani
Saeed Soltani 2016 年 2 月 11 日
Thanks for your quick answer, but as I have already tried, it does not work. However the last line needs a small correction:
set(hBlock,'Position', Position+10);
But the problem is each time by clicking, the position will be reset to the initialized value and it gives back the same value of Position+10.
Fangjun Jiang
Fangjun Jiang 2016 年 2 月 11 日
Please see the update

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlock Libraries についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by