Cell Function
1 回表示 (過去 30 日間)
古いコメントを表示
I've created a sliding window using the cell function. I used this as I am creating the sliding window for a daily time series of data over a few hundred years. The sliding window is 30 years long and because of leap years each row is a different length. So I now have an array of data that looks like this:
data =
10957x1 double
10957x1 double
10958x1 double
and so on...
I'm unfamiliar with the cell function however as this code was shown to me. How do I now use the data in this series? Whenever I type the command for example:
data (1,1)= 10957x1 double
But I need to do a number of things such as take the mean of each vector in the array, how do I do this?
0 件のコメント
採用された回答
Wayne King
2011 年 10 月 3 日
x = {randn(1000,1), randn(1000,1), randn(1000,1)};
meanz = cellfun(@mean,x,'UniformOutput',false);
meanz = cell2mat(meanz);
5 件のコメント
Jan
2011 年 10 月 3 日
@James: Use curly braces to access cell elements:
for 1:n, mean(data{n,1}), end
for 1:n, detrend(data{n,1}), end
その他の回答 (5 件)
Andrei Bobrov
2011 年 10 月 3 日
data2 = cellfun(@(x){mean(x) detrend(x)},x,'un',0)
ADD
data2 = cellfun(@(x)[mean(x);detrend(x)],x,'un',0)
datadouble = [data2{:}];
datamean = datadouble(1,:)
datadetrend = datadouble(2:end,:);
Wayne King
2011 年 10 月 3 日
You can use two calls to cellfun and then use cell2mat
data1 = cellfun(@mean,x,'UniformOutput',false);
data1 = cell2mat(data1);
data2 = cellfun(@detrend,x,'UniformOutput',false);
data2 = cell2mat(data2);
2 件のコメント
Wayne King
2011 年 10 月 3 日
Notice that data2 contains the detrended data as column vectors, which you can plot()
plot(data2)
data1 is a row vector of means
Fangjun Jiang
2011 年 10 月 3 日
Since data is a cell array, you need to use {} to reference its element, like data{1}, data{2}, data{3}, etc.
data{1} will be a 10957x1 double array, to reference its element, use data{1}(1), data{1}(100), data{1}(10957), etc.
You need to understand these basics. See http://www.mathworks.com/help/techdoc/learn_matlab/f4-2137.html#f4-2245
0 件のコメント
James
2011 年 10 月 3 日
2 件のコメント
Fangjun Jiang
2011 年 10 月 3 日
Why need meancell = cellfun(@(T32)mean(T32),T32,'un',0)
Can it be meancell = cellfun(@mean,T32,'un',0)
Wayne King
2011 年 10 月 3 日
Why didn't you do what I suggested?
detrendcell = cellfun(@(T32)detrend(T32,'linear'),T32,'un',0);
detrendcell = cell2mat(detrendcell);
By the way, 'linear' is the default option for detrend:
so
detrendcell = cellfun(@detrend,T32,'UniformOutput',false);
detrendcell = cell2mat(detrendcell);
The above returns a matrix whose columns are your detrended series.
Is the same and a bit cleaner.
5 件のコメント
Wayne King
2011 年 10 月 3 日
Transpose your input
T32 = T32';
detrendcell = cellfun(@detrend,T32,'UniformOutput',false);
detrendcell = cell2mat(detrendcell);
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!