multi-level/recursive assignment subsasgn example in matlab

preview_player
Показать описание

Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!multi-level/recursive assignment subsasgn example in matlab

I am writing a matlab class and would like to overwrite the subasgn operator to achieve this
subasgn
obj.('elem1').('subelem1').('subsubelem1')=val;

obj.('elem1').('subelem1').('subsubelem1')=val;

where the level of depth can vary. This type of multi-level assignment is supported in standard struct (but not in containers.Map or dictionary).
struct
containers.Map
dictionary
from the below link, I found examples for writing a subsasgn for only 1 subfield level, but it does not support multiple levels as struct does
subsasgn
I am wondering if anyone can give some pointers on how to achieve this?
thanks
Update: [09/26/2024]
Update: [09/26/2024]
my sample code can be found in
specifically, the subsref() function can retrieve multi-level subkeys on both MATLAB and Octave.
subsref() function
subsref()
however, the subsasgn function can only modify the value for only one level of subfield
subsasgn function
subsasgn
Update: [09/28/2024]
Update: [09/28/2024]
following the code sample suggested by rahnema1, the subsasgn in my jdict class can set subkey values at any level, and also allows to append new keys. the code can be found at
code sample suggested by rahnema1
subsasgn

Tags: matlab,operator-overloading,octaveSource of the question:

Question and source license information:
Рекомендации по теме