Weffel
Weffel

Reputation: 133

How can you get/compare values of a struct in the UserData of a MATLAB/Simulink block

In MATLAB/Simulink I got a Simulink model with blocks, there I have put a struct into the UserData of a block. How can I get or compare something with the data inside the struct?

I made it like this:

my_struct = struct('Function', 'receive', 'Version', '0.1');
set_param(gcb, 'UserData', my_struct);

Now how can i check in my matlab script which of the blocks that i found with:

all_blocks = find_system(gcs, 'Tag', 'All_blocks_have_this_tag');

have the value 'receive' in their 'UserData'.'Function'?

Upvotes: 1

Views: 225

Answers (1)

Weffel
Weffel

Reputation: 133

I found it, you can use get_param() to get the blocks but that returns it in cells, not in a struct. So if you acces the cell with {1,1} then you can acces the struct from there

param = get_param(blocks(i), 'UserData');
param{1,1}.Function

this will return the value of Function of the struct in the UserData of the block

Upvotes: 1

Related Questions