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

23 ビュー (過去 30 日間)
Nouran Adel
Nouran Adel 2019 年 7 月 14 日
コメント済み: Nouran Adel 2019 年 7 月 29 日
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 Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by