How to retrieve 100 highest coefficient from <1x1024> cell array

1 次查看(过去 30 天)
for i=1:1024
c12mean{i}=mean2(cv1{1,2}{1,i});
end
c12mean array contain mean values stored in &nbsp<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

回答(1 个)

Stephen23
Stephen23 2015-5-17
编辑:Stephen23 2015-5-17
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:
  • 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.
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".

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by