Change struct property values in a class
Mostra commenti meno recenti
Hi, I have a problem with using a struct as property of a value class. It seems I cannot change the values of fields (or add new fields).
The simplest example is as follows:
classdef testclass
properties
struct_prop=struct;
end
methods
function obj = change_struct_prop(obj, val)
obj.struct_prop.field1 = val;
end
end
end
Trying to change the struct_prop doesn't work:
>> a=testclass;
>> a.change_struct_prop(2);
>> a.struct_prop
ans =
field1: []
>>
Is there any way to manipulate a class property that is a struct (without having to define a separate class for it)? Defining the struct_prop fields in the initialisation function didn't help either.
Thanks a lot,
Olf
Risposta accettata
Più risposte (1)
Olf
il 6 Nov 2014
1 voto
Categorie
Scopri di più su Scope Variables and Generate Names in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!