Update field value in structures?
10 views (last 30 days)
Najmeh Eskandari on 10 Feb 2019
I have structure L with field L0. L0 has two fields:H0 and H1.
relevant_L.H0.Q_centroids=[-pi/2,0,pi/2,0;1 5 4 2];
I want to update H0 and then save it in L. so i load L0(relevant_L=L.L0) then update it through the last line but new strcture is created(name:relevant_L).
i know we can do this by:
but i want to change Q_centroids first by load L.L0 in another variable(relevant_L) and then change it.
Is it possible?
Walter Roberson on 10 Feb 2019
If the question is whether it is possible to create an "alias" to something inside a structure, such that assigning to the name will have the effect of changing the part inside the structure -- if that is the question, then the answer is NO, that cannot be done in MATLAB with struct
That said, something that would look like that can be done in MATLAB. It would require that L0 would be an object of a class derived from handle and that the class had a H0 property. In that particular configuration, then updating relevant_L.H0 would have the effect of updating L.L0.H0 .