How to apply certain action on struct fields?
显示 更早的评论

Hello, I have a variable, "vidTMP", it's a structure.
It's movie frames. Each frame is 1080x1920x3 uint 8. Field name is cdata.
I'd like to perform "rgb2gray" on all of the frames in one code command. Is it possible?
Maybe "structfun"? I've tried, but seem to have some syntax error...
At the moment I'm using the following for-loop. Is there any more elegant alternative?
firstFrame = vidTMP.cdata;
vidTMP2 = zeros(size(firstFrame,1),size(firstFrame,2),length(vidTMP));
for i = 1 : length(vidTMP)
vidTMP2(:,:,i) = vidTMP(i).cdata(:,:,1);
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!