Dot indexing is not supported for variables of this type in a for loop

20 views (last 30 days)
Hi , I'm trying to get data from a simulink model and print it in matlab workspace . so first I loaded the model using : load_system('C:/Users/nouu_/Desktop/model.slx') then I got the blocks that are in the model using : bl = getfullname(Simulink.findBlocks('model')) , then I used the following commands to know the input and output of each block , I mean to know which block is connected to the input or output of each block , in the following lines I'm using the block "Pipe Bend" as an example :
b = get_param('model/Pipe Bend','PortConnectivity')
n=numel(b)
for k=1:n
s=get(b(k).SrcBlock);
f='Source';
if isempty(s)
s=get(b(k).DstBlock);
f='Destinataion';
end
out{k,1}=f;
out{k,2}=s.BlockType;
out{k,3}=s.Name
end
disp(out)
but whenever I execute this for loop I get the following error : Dot indexing is not supported for variables of this type.
and another question : is there something wrong with this for loop ? as in some cases like the case of this pipe it prints that other 2 blocks are connected to its output(destination) whichis wrong because one block is input and the other is output .
any help is appreciated , Thanks

Accepted Answer

Guillaume
Guillaume on 14 Jul 2019
Typically, you'll get this error because the structure or object you're indexing with . is empty.
Indeed, you have this bit of code:
s=get(b(k).SrcBlock);
if isempty(s) %so get(b(k).SrcBlock) returned empty
s=get(b(k).DstBlock); %and you're asking for the same again, which is still going to be empty
end
out{k,2}=s.BlockType; %errors if s is empty
So, you test for s being empty, but if it is you call exactly the same function that returned empty, so it's still going to be empty. Hence the error when you index s.
I don't know simulink so can't really tell what you're trying to do, but clearly your logic is wrong.
  1 Comment
Nouran Adel
Nouran Adel on 29 Jul 2019
yes you are right I've put some blocks in simulink but I have not connected all their ports to other blocks so some ports are empty and maybe this is why this error appears . Thanks :)

Sign in to comment.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!