How to find max,min,average values from a cell array?
45 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I have a cell array of size 1x316 which further contains multidimensional cell arrays.
Each cell array is of different sizes like 1xa, 1xb, 1xc and so on.All values inside the cell arrays are double numeric type.
I want to find max, min , average values from each cell array and finally save the output in 3 different
cell arrays of sizes 1x316 say max_pause_duration(1x316), min_pause_duration(1x316) and mean_pause_duration(1x316).
Initially i have stored cell array in s2 which is a 1x1 struct with one field ->pause_duration of size 1x316.
The cellfun function works very slow as its a big data.
Please help me out on this.
s2 = load('pause_durations_rome.mat');
max_pause_time =cell(size(s2.pause_duration));
min_pause_time = cell(size(s2.pause_duration));
average_pause_time = cell(size(s2.pause_duration));
for iter = 1:length(s2.pause_duration)
a=cell2mat(s2.pause_duration,);
max_pause_time{iter} = max(a(:));
min_pause_time{iter} = min(a(:));
average_pause_time{iter} = mean(a(:));
end
0 Commenti
Risposta accettata
Azzi Abdelmalek
il 30 Mar 2016
Modificato: Azzi Abdelmalek
il 30 Mar 2016
A={ num2cell(rand(1,4)) num2cell(rand(1,5))}
out1=cellfun(@(x) min(cell2mat(x)),A)
out2=cellfun(@(x) max(cell2mat(x)),A)
out3=cellfun(@(x) mean(cell2mat(x)),A)
Più risposte (1)
Venkat Ta
il 23 Lug 2019
Hi really nice function works fine but inside the cell 6*30double how i get the mean, max, and min?![Screen Shot 2019-07-23 at 10.44.25 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231018/Screen%20Shot%202019-07-23%20at%2010.44.25%20PM.png)
![Screen Shot 2019-07-23 at 10.44.25 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231018/Screen%20Shot%202019-07-23%20at%2010.44.25%20PM.png)
0 Commenti
Vedere anche
Categorie
Scopri di più su Structures 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!