direct access to the result of a function call
Mostrar comentarios más antiguos
Hi,
Is there any way to write this code
" portdata=get_param(gcb,'PortConnectivity')
In1Src=portdata(1).SrcBlock
" in this way
" In1Src=get_param(gcb,'PortConnectivity') (1).SrcBlock
" ?
I need to do that 'cause my prof (advisor of my internship) told me to do that, he doesn't want too many variables in the workspace, because in his opinion they can interfere with the proper functioning of the other blocks, that means I must avoid to create portdata
thank a lot 4 reading let me know if you have any idea
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 24 de Feb. de 2012
Here is the code you need in order to avoid creating a named temporary variable:
In1Src = subsref( subsref(get_param(gcb,'PortConnectivity'), struct('type',{'()'},'subs',{{1}})), struct('type',{'.'},'subs',{'SrcBlock'}) );
Reading that is "cruel and unusual punishment" in my opinion.
Your existing code of
portdata = get_param(gcb,'PortConnectivity');
In1Src = portdata(1).SrcBlock;
differs from the above only in that it creates an explicit name for a temporary data structure that goes unnamed in the longer and difficult to read code. If you do not want the temporary variable to be kept, use your existing code but add
clear portdata
I do not recommend explicit use of subsref() when it is avoidable. I only show it here in order to demonstrate that it is possible but that it is the programming equivalent of a tension headache.
1 comentario
grapevine
el 27 de Feb. de 2012
Categorías
Más información sobre Web Services en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!