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

조회 수: 16 (최근 30일)
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

채택된 답변

Guillaume
Guillaume 2019년 7월 14일
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
Nouran Adel
Nouran Adel 2019년 7월 29일
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 :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by