preallocation

조회 수: 2 (최근 30일)
Duke Watson
Duke Watson 2012년 6월 3일
hey guys, i am new at MATLAB, I have problem in preallocating the space for the variable'M' in the following statement:
for i=1:10000
M(i-1)=im2frame(int8(fg),gray(256));
I don't know what is the diminsion of this structure or the statement for preallocating space for M

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 3일
A "frame" is a structure with the fields "cdata" and "colormap"
You should be able to preallocate with
M(10000) = struct('cdata', {[]}, 'colormap', {[]} );
Caution: in your code, you try to store into M(i-1) when "i" starts at 1. That is going to try to store into M(0) which is not a valid index for MATLAB arrays: indices must be at least 1
  댓글 수: 4
Duke Watson
Duke Watson 2012년 6월 3일
Sorry,i didn't get you.
I think all the frames all of the same size as i have extracted frames from a video and convert them into gray image and then again convert them into frames and then finally into video.(Frame Difference Algorithm).
Now if you get me,please tell me what should i do?
Walter Roberson
Walter Roberson 2012년 6월 3일
T1 = arrayfun( @(S) size(S.cdata), M, 'Uniform', 0);
T2 = cell2mat(T1(:));
T3 = unique(T2, 'rows');
T4 = size(T3,1);
fprintf(1, 'You have %d different sizes of frames\n', T4);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by