Fast method of Initialization of logicals into cells
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Walter Roberson
il 20 Lug 2011
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 Commenti
Walter Roberson
il 20 Lug 2011
Corrected in my code, thanks. Note thought that that gives an actual 1x1 logical value, not an empty logical.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!