1
votes

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'?

1
You could use find_system to get all blocks, then check the parameter. I am not aware of any better solution.Daniel
yeah i tried that, but i couldn't get the parameter to give me a good value, turns out i got a cell returned, not a struct...Weffel

1 Answers

1
votes

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