フィルターのクリア

How to calculate max,min,average values from a cell array?

5 ビュー (過去 30 日間)
Jung BC
Jung BC 2016 年 3 月 17 日
コメント済み: Jung BC 2016 年 3 月 21 日
Hi, I have a cell array of size 1x316 with each cell of different sizes.All values in the cells are double numeric type.I want to find max, min , average values from each cell and save in a different cell arrays of sizes 1x316. This is my code for now:
I have stored cell array in struct s2.This cell array is of sie 1x316.I am trying to return max,min and avg values from a single for loop and saving outputs in 3 different cell arrays.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

回答 (1 件)

Adam
Adam 2016 年 3 月 17 日
編集済み: Adam 2016 年 3 月 17 日
min_pause_time = cellfun( @min, s2.pause_duration);
max_pause_time = cellfun( @max, s2.pause_duration );
average_pause_time = cellfun( @mean, s2.pause_duration );
  13 件のコメント
Stephen23
Stephen23 2016 年 3 月 20 日
A non-scalar structure makes this trivial to implement:
S(1).user = 'anna';
S(2).user = 'bob';
S(3).user = 'chen';
...
S(1).data = [0,1,2];
S(2).data = [3,4,5,6];
S(3).data = [7,87,9];
You can add as many users as you need, and any fields that you want. And then accessing the data is very simple:
>> users = {S.user}
users =
'anna' 'bob' 'chen'
>> S(strcmp(users,'bob')).data
ans =
3 4 5 6
You are writing the code and extracting the data, so if you want to make your own life easier then simplify your data organization.
Jung BC
Jung BC 2016 年 3 月 21 日
Thanks Stephen, now i got the picture.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by