【发布时间】:2012-02-16 10:02:19
【问题描述】:
我有以下脚本用于将文本文件导入 matlab,其中包括每小时数据,然后我尝试将它们转换为每日平均值:
clear all
pathName = ...
TopFolder = pathName;
dirListing = dir(fullfile(TopFolder,'*.txt'));%Lists the folders in the directory specified by pathName.
for i = 1:length(dirListing);
SubFolder{i} = dirListing(i,1).name;%obtain the name of each folder in
%the specified path.
end
%import data
for i=1:length(SubFolder);
rawData1{i} = importdata(fullfile(pathName,SubFolder{i}));
end
%convert into daily averages
rawData2=cell2mat(rawData1);
%create one matrix for entire data set
altered=reshape(rawData2,24,(size(rawData2,2)*365));
%convert into daily values
altered=mean(altered)';
%take the average for each day
altered=reshape(altered,365,size(rawData2,2));
%convert back into original format
我的问题在于尝试将数据转换回与“rawData1”相同的格式,这是每个变量的一个单元格(每个变量都由“SubFolder”表示。这样做的原因是除了一个变量为向量,其余变量为矩阵(8760*11)。
所以,这方面的一个例子是:
clear all
cell_1 = rand(8760,1);
cell_2 = rand(8760,1);
cell_3 = rand(8760,1);
cell_4 = rand(8760,1);
cell_5 = rand(8760,1);
cell_6 = rand(8760,11);
cell_7 = rand(8760,1);
cell_8 = rand(8760,1);
cell_9 = rand(8760,1);
data = {cell_1,cell_2,cell_3,cell_4,cell_5,cell_6,cell_7,cell_8,cell_9};
我需要将“数据”中的每个单元格从每小时值转换为每日平均值(即 365 行)。
任何建议将不胜感激。
【问题讨论】: