- instead of nesting everything in cell arrays (like other languages do), learn to use the dimensions of numeric arrays. This is much faster to process and often does not require looping!
- learn how to write vectorized code.
- learn to preallocate arrays.
How to retrieve 100 highest coefficient from <1x1024> cell array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
for i=1:1024
c12mean{i}=mean2(cv1{1,2}{1,i});
end
c12mean array contain mean values stored in  <1x1024> cell array.
for i=1:1024
C12SortVal{i} = unique(c12mean{1,i}(:));
C12_max100_mean{i} = mean2(C12SortVal{i}(end-99:end));
end
The above coding work for matrix. How can i change the coding for cell array
0 Commenti
Risposte (1)
Stephen23
il 17 Mag 2015
Modificato: Stephen23
il 17 Mag 2015
Although beginners seem to think that storing everything in cell arrays is a great idea, MATLAB because a much faster and more convenient tool when you learn to store data properly. Just like with every programming language there are efficient and inefficient ways of storing data in MATLAB. While cell arrays are great if you need them, they should not be the first choice for storing numeric data.
MATLAB offers many useful tools for doing fast and efficient processing of numeric arrays. This is in many ways its most powerful feature, so when you choose to store data nested within cells arrays or structures it only makes everything slower and more complicated to do basic numeric calculations on.
This entire question could be resolved easily using a few lines, and no loops, if the arrays were numeric.
A few points to consider:
Often when these kind of questions arise "how do I find the maximum in this cell array" (or something similar) the most efficient answer is anyways "concatenate all of the data into one numeric array, the use the inbuilt functions".
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical 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!