Assign multiple fields to a Struct-Array
显示 更早的评论
hi, I'm new to struct Arrays and I've got the following problem:
filelist(:).names = upper(filelist(:).names);
somehow I cannot figure out how to tell matlab to assign each result of the upper function to one entry in the filelist. I'm sure that there's a simple solution but I understand how until now
Thanks!
回答(3 个)
Fangjun Jiang
2011-9-9
filelist(1).names='a';
filelist(2).names='b';
a=upper({filelist.names});
[filelist.names]=deal(a{:})
2 个评论
Andrei Bobrov
2011-9-9
+1
[filelist.names]=a{:}
Fangjun Jiang
2011-9-9
Thanks, andrei! deal or no deal!
Andrei Bobrov
2011-9-9
for j1 = numel(filelist):-1:1
filelist(j1).names=upper(filelist(j1).names);
end
variant with arrayfun and others
filelist = ...
cell2struct(arrayfun(@(x)upper(x.names),filelist,'un',0),fieldnames(filelist));
Vincent
2011-9-9
0 个投票
3 个评论
Jan
2011-9-9
Why do you want to avoid the loop??
Vincent
2011-9-9
Fangjun Jiang
2011-9-9
So, is my answer above what you are looking for?
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!