How can I change the variable name of "to workspace" dynamically ?

4 views (last 30 days)
My question was showed in a picture. https://www.opendrive.com/files/?Ml8yOTY2NjJfa0Z4Z3E fig1 is a block I have established.fig2 is the input panel(NUM).In a system I need many A block,but has a"To Workspace"in A will error. I hope if I give a NUM is "1" ,the "To Workspace" can change its Variable name into "A_out1" automatically,and if the NUM input is "2" it can be changed into "A_out2".

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 15 Dec 2011
I would recommend you go back to your previous question and follow the advice regarding data logging. My comment regarding "mask parameter could be a workaround" is really for the sake of argument. Your approach of putting a "To Workspace" block inside a customized library block is non-typical. It can be made to work with mask parameter but it is a stretch.
However, to prove it can be done, I'll show you the method here. Still, I strongly recommend that you use other data logging method. The worst case, is that you can choose not to put the "To Workspace" block inside the customized library block. Rather, you can put the "To Workspace" block outside of the reference block in the model.
Assume you added a mask parameter called 'VarNum' which is an 'edit' type, and the name of the "To Workspace" block inside is still called "To Workspace", you can add the following line in the "Dialog callback" of the mask parameter 'VarNum'.
set_param([gcb,'/To Workspace'],'VariableName',['A_Out',get_param(gcb,'VarNum')]);
  1 Comment
li xinjun
li xinjun on 15 Dec 2011
Thank you for your help again.I have read your previous answer.But my English is not very well,so I can't understand it well.Because I must finish my assignment in time,so I hope a easier workaround.Thank you for your help.I will carefully study your previous answer.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!