How to extract some values from a structure?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Benson Gou
am 10 Jun. 2021
Kommentiert: Benson Gou
am 10 Jun. 2021
Dear All,
I have a structure A which has several fields. Each field has 100 values. I want to extract the first 20 values from each field and save them in a structure B. I tried to use the following code:
B = A(1:20).
It does not work. Would you please tell me how I can get structure B?
Thanks.
Benson
Akzeptierte Antwort
Stephen23
am 10 Jun. 2021
Assuming that structure A is scalar (so far you did not tell us this important information):
A.x = randi(9,1,100);
A.y = randi(9,1,100);
A.z = randi(9,1,100)
fun = @(v)v(1:20);
B = structfun(fun,A,'uni',0)
Weitere Antworten (0)
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!