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

20 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Guillaume
Guillaume el 14 de Jul. de 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 comentario
Nouran Adel
Nouran Adel el 29 de Jul. de 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 :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by