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
Fangjun Jiang 2011년 9월 9일

4 개 추천

filelist(1).names='a';
filelist(2).names='b';
a=upper({filelist.names});
[filelist.names]=deal(a{:})

댓글 수: 2

Andrei Bobrov
Andrei Bobrov 2011년 9월 9일
+1
[filelist.names]=a{:}
Fangjun Jiang
Fangjun Jiang 2011년 9월 9일
Thanks, andrei! deal or no deal!

댓글을 달려면 로그인하십시오.

Andrei Bobrov
Andrei Bobrov 2011년 9월 9일

0 개 추천

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
Vincent 2011년 9월 9일

0 개 추천

Is there also a solution avoiding the loop?

댓글 수: 3

Jan
Jan 2011년 9월 9일
Why do you want to avoid the loop??
Vincent
Vincent 2011년 9월 9일
less lines, nicer code and isn't it often faster to use vecorization (if possible)
anyway thank you very much for your nice answers!
Fangjun Jiang
Fangjun Jiang 2011년 9월 9일
So, is my answer above what you are looking for?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2011년 9월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by