Changing field value for all fields in a struct
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MiauMiau
am 3 Apr. 2014
Kommentiert: deejt
am 19 Jan. 2021
Hi
Given for instance I have a struct as follows:
s(2) = struct('name','anna','age',18)
s(1) = struct('name','bernd','age',22)
Now I want to change all the names to 'unknown', i.e. as well for s(1) as for s(2). How can I do it (this is just a toy example, I do have a 123 dimensional struct where I do not want to do it one by one). Thanks
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 3 Apr. 2014
s(2) = struct('name','anna','age',18)
s(1) = struct('name','bernd','age',22)
n=numel(s)
for k=1:n
s(k).name='unknown'
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!