How to extract some values from a structure?
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
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
采纳的回答
  Stephen23
      
      
 2021-6-10
        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)
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

