Fast method of Initialization of logicals into cells
1 回表示 (過去 30 日間)
古いコメントを表示
Hi....i'd like to make a large cell array (that contains empty logicals) and i want to see if theres anyway to do it faster than the way im currently doing it....
my way is described below...
temp_allzeros = false(size(config.MIDlist,1),1);
allzeros = cell(size(config.MIDlist,1),1);
for i = 1:length(temp_allzeros)
allzeros(i) = temp_allzeros(i);
end
0 件のコメント
採用された回答
Walter Roberson
2011 年 7 月 20 日
You cannot set a cell array entry to a logical value.
>> bar = cell(3,1)
bar =
[]
[]
[]
>> bar(1) = false
??? Conversion to cell from logical is not possible.
In your code, there is no point using temp_allzeros as an array since every member is the same. Your code could be replaced with
allzeros = cell(size(config.MIDlist,1),1);
for i = 1:length(temp_allzeros)
allzeros{i} = false;
end
But faster would be
allzeros(1:size(config.MIDlist,1)) = {false}; %corrected per Sean
Note, though, that in your original code and in my code, the cell entries are set to actual logicals, not the empty logical. So you need to jigger the code more:
allzeros(1:size(config.MIDlist,1)) = {false(0,0)};
As you asked about "faster", you might want to do timing tests to compare
[allzeros{1:size(config.MIDlist,1)}] = deal(false(0,0));
2 件のコメント
Walter Roberson
2011 年 7 月 20 日
Corrected in my code, thanks. Note thought that that gives an actual 1x1 logical value, not an empty logical.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!