Dot indexing is not supported for variables of this type in a for loop
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nouran Adel
am 14 Jul. 2019
Kommentiert: Nouran Adel
am 29 Jul. 2019
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
0 Kommentare
Akzeptierte Antwort
Guillaume
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!