preallocation
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
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 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!