Hi I have this code. It produces a 30 year sliding window for my data. The data is daily over around 230 year and the code puts it in a cell array 208x1 with each cell around 10958x1 and I'm having an issue with cell2mat whereby it takes all of my data and puts it in one column rather than the 208 it should be in. How can I solve this?
%%Data Loading
close all
clear all
cet = load ('cet_1772_2009.asc', '-ascii'); % Loads CET from asc file.
year = cet(:,1);
temp = cet(:,4);
day = cet(:,3);
month = cet(:,2);
% Loads Data from CET asc file and sets vectors
%%Constants and vectors
dates = datenum([year,month,day]);
%%30 Year Periods
StartYear=1772;
EndYear=2009;
Period=30;
T32=cell(EndYear-StartYear-Period+1,1);
for Year=StartYear:(EndYear-Period)
StartCount=datenum(Year,1,1)-datenum(StartYear,1,1)+1;
DataCount=datenum(Year+Period,12,31)-datenum(Year,12,31);
T32{Year-StartYear+1}=temp(StartCount:(StartCount+DataCount),1);
end
%%Detrend, mean etc
meancell = cellfun(@(T32)mean(T32),T32,'un',0);
meanT = cell2mat(meancell);
detrendcell = cellfun(@detrend,T32,'UniformOutput',false);
detrendcell = cell2mat(detrendcell);

1 件のコメント

James
James 2011 年 10 月 3 日
10958x1 is an estimate, 30 year periods vary in length by 1 or 2 days due to leap years

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

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 3 日

0 投票

The cells in your data meancell and detrendcell have different length of data, that is why they have to be in a cell array. You can reference its data using {} and (), meancell{2}(100) for example. Why do you want to use cell2mat()? What is the purpose and your expected outcome?

5 件のコメント

James
James 2011 年 10 月 3 日
I need to do operations on the data with programming I have that is not set up for cell arrays so it would be really handy to have it in that format?
Wayne King
Wayne King 2011 年 10 月 3 日
sorry! I missed in your previous post that your data vectors were different sizes. In that case Fangjun's suggestion is absolutely correct.
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 3 日
The result of cell2mat() is a matrix. Matrix has a fixed size. You can't have a matrix that has different number of rows for each column.
How do you want the structure of your data look like? Can you make a simple example, considering they have slightly different number of rows?
James
James 2011 年 10 月 3 日
For example I need to access each value in the array to check if it is greater than a certain value. However I can't get an if statement does not appear to work with a cell array
Here's my code for this:
for m=1:208
for n=1:10959
if detrendcell{m}(n)>mu(m)
burstdur(m,n) = 1;
end
end
end
and the error I get is:
??? Undefined variable "detrendcell" or class "detrendcell".
Error in ==> Untitled2 at 43
if detrendcell{m}(n)>mu(n)
James
James 2011 年 10 月 3 日
My bad that was an issue with something else, it just appeared that way. Thanks for all your help guys, has been very useful!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by