필터 지우기
필터 지우기

How to use get_param?

조회 수: 32 (최근 30일)
Diana Acreala
Diana Acreala 2011년 10월 3일
Hi!
I have a complex Simulink model in which I used 200-300 parameters.
My question comes with the following example: I am using a constant block in my Simulink model. 1) As you know, when you double click on the block you can see in the 'Main' tab the field 'Constant value' that can contain a value (e.g. 8) or a parameter name (e.g. 'my_parameter_name'). What I want is to get in Matlab workspace this name. I used: h=load_system('my_model') constant_blocks=find_system(h,'SearchDepth',2,'LookUnderMasks','all','FindAll','on','BlockType','Constant'); para_name=get_param(constant_blocks,'Value')
This will return the value of my_parameter_name. What I want is to get the name, not the numeric value. How can I do that??
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2011년 10월 3일
That doesn't sound right. If the dialog contains a variable name for Value, get_param should return a string containing the same variable name (which is what you need). Perhaps you should verify that the corresponding Constant block does indeed use the variable name?

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

답변 (3개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 3일
I think your find_system() line probably will return many blocks. You need to narrow it down.
Or just use a simple example, drag and drop a Constant block, double click it, type in "MyPara" as its value, then in Command Window, run
get_param(gcb,'Value')
  댓글 수: 2
Diana Acreala
Diana Acreala 2011년 10월 3일
Hmm...I'm using a lot of constant blocks, normally I want to get all the parameter names used, so I need to get first all my constant blocks as I did with:
constant_blocks=find_system(h,'SearchDepth',2,'LookUnderMasks','all','FindAll','on','BlockType','Constant');
Fangjun Jiang
Fangjun Jiang 2011년 10월 3일
That's fine. Then what is the problem using get_param()? Did you try it on a single Constant block to verify it first?

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


Rajan
Rajan 2011년 10월 3일
constant_blocks=find_system(h,'SearchDepth',2,'LookUnderMasks','all','FindAll','on','BlockType','Constant'); const_value=[];
for i=1:length(constant_blocks)
const_value=[const_value get_param(constant_blocks(i),'Value')];
end
i hope this one works..
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 10월 3일
No. You don't need the for-loop. get_param() can take array of handles and return results in a cell array.

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


Diana Acreala
Diana Acreala 2011년 10월 4일
It gives me the same thing... numeriv values, not the name... is there another solution?
  댓글 수: 3
Diana Acreala
Diana Acreala 2011년 10월 4일
Nothing that helps me... What is this?
Fangjun Jiang
Fangjun Jiang 2011년 10월 4일
f14 is a Simulink model provided by TMW. I am showing that get_param() will be able to get the variable name, not numeric value. If you run the two lines, you will get the answer. That will solve the problem in your question. I don't understand why you are so struggle with such a simple task.

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

카테고리

Help CenterFile Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by