MATLAB: How to add a new field in astruct struct test=struct('generated_power',genPwr,'Platform_motions',PlatMotions) How can I add a new field to my "test"-struct between runs? Best Answer setfield(test,'NewField',1) Related SolutionsMATLAB: Add a new field to structure teststruct = struct('names',{'bob','dave','sara'}); % now add field called data [teststruct(:).data] = deal(randn(3,1)); fieldnames(teststruct) MATLAB: How to make a structure to be input of a function and then its updated version to be output of the function function new_struct = update_struct(old_struct,add_field, add_val) new_struct = old_struct; new_struct.(add_field) = add_val;endNotes:"function" comes before outputdon't use struct as a variable name Related QuestionAdding new field to structure arrayComparing two structures and find the commonHow to create a structure inside a structureHow to rename fields in struc and adding new field name
Best Answer