How to programmatically comment/uncomment a Simulink block?

Simulink blocks can be commented/uncommented using Ctrl+Shift+X.
Is there a way to do this programmatically in a Matlab script?

댓글 수: 3

RAGHUVEER RAJESH
RAGHUVEER RAJESH 2023년 9월 21일
편집: RAGHUVEER RAJESH 2023년 9월 21일
Yes. there is and I found it out just now after I explored your question :))) in 2015 I was 17 years old and today I am pursuinig my Masters in Engineering.... Wooh!! That was a long time ago!!!... ;-)
Well the answer is: The path value has to be passed as a string. So put the path in ' ' single inverted commas.
Detailed answer with example given below this question.
Answer:
Please let me know if it helps... Have a nice day! Thanks.
how to pogrammatically comment and uncomment all the blocks in the simulink model ?
@Akhilesh I am not sure if the following works:
ModelName = 'my_model.slx'; % here you put the name of your Simulink model
set_param(ModelName,'Commented','on')
set_param(ModelName,'Commented','off')
Because in documentation it only mentions about commenting out a block. But even so be the case, you can simply engulf your whole model into a Subsystem and simply comment out that Subsystem block.

댓글을 달려면 로그인하십시오.

 채택된 답변

Sebastian Castro
Sebastian Castro 2015년 12월 9일
Yes, you can do
set_param(blockName,'Commented','on')
set_param(blockName,'Commented','off')
... or if the block has 1 input and 1 output port, you can also comment through
set_param(blockName,'Commented','through')
Here, blockName is the name of the block, which you can obtain by selecting the block and typing gcs.
- Sebastian

댓글 수: 3

Joe
Joe 2015년 12월 9일
이동: Walter Roberson 2024년 2월 12일
Perfect! Thank you, again.
If it's in the docs I couldn't find it...
To add to this, it can save an additional step by selecting the block and typing "gcb" instead of "gcs".
Excellent. I was lost in the myriad parameters each block / component has.
set_param([gcs,'/L(',num2str(k),')'],'Commented','on')
selects L(k) from the current system and comments it out.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

RAGHUVEER RAJESH
RAGHUVEER RAJESH 2023년 9월 21일
편집: RAGHUVEER RAJESH 2023년 9월 21일

0 개 추천

The path value has to be passed as a string. So put the path in ' ' single inverted commas.
For e.g.
set_param('subsystempath','Commented','on')
set_param('subsystempath','Commented','off')
the 'subsystempath' is full path to that subsystem. For e.g. 'modelName/subsystemName...'
If it helps, please let me know...

카테고리

도움말 센터File Exchange에서 Subsystems에 대해 자세히 알아보기

태그

질문:

Joe
2015년 12월 9일

댓글:

2024년 10월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by