フィルターのクリア

A vectorisation problem with arrays (or matrices) and structs

1 回表示 (過去 30 日間)
MechtEngineer
MechtEngineer 2011 年 10 月 12 日
I have a m x n x p array, consisting of 'p' frames of height 'm' and width 'n' from a movie file. I want to assign all of the images in the array to a struct without using a 'for' loop.
i.e. my code is:
videoHeight = size(movieMatrix,1);
videoWidth = size(movieMatrix,2);
totalFrames = size(movieMatrix,3);
movieStructure(totalFrames).cdata = zeros(videoHeight,videoWidth);
movieStructure(1:totalFrames).cdata = movieMatrix(:,:,1:totalFrames);
instead of:
movieStructure(totalFrames).cdata = zeros(videoHeight,videoWidth);
for i = 1:totalFrames
movieStructure(i).cdata = movieMatrix(:,:,i);
end
I have looked at pages on vectorisation, but I can't find any examples that helps me with structs and arrays together. I appreciate help that anyone offers!

採用された回答

Walter Roberson
Walter Roberson 2011 年 10 月 12 日
movieStructure = struct('cdata', mat2cell(movieMatrix,videoHeight,videoWidth,ones(1,totalFrames)) );

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by