我有一个大小为 1x7 的单元格,其中每个单元格的大小为 365x5xN,其中每个 N 都是不同的位置 (siteID)。它已根据第 5 列排序(这些列为纬度、经度、siteID、日期和数据)。 (数据可以在这里找到:https://www.dropbox.com/sh/li3hh1nvt11vok5/4YGfwStQlo。有问题的变量是 PM25)
我想遍历整个 1x7 单元格,并仅查看前 36 行(基本上是前 10 个百分位数),计算每个日期出现的次数。换句话说,我想知道哪些天的数据值落在前 10 个百分位内。
有人知道我该怎么做吗?我不知道如何解决这个问题 --> 计算所有这些单元格并吐出一年中每一天的数量
最佳答案
假设您有一个已排序的元胞数组,您可以使用它 -
%%// Get all the dates for all the rows in sorted cell array
all_dates = [];
for k1=1:size(sorted_cell,2)
all_dates = [all_dates reshape(cell2mat(sorted_cell{1,k1}(:,4,:)),1,[])];
end
all_unique_dates = unique(all_dates);
all_out = [num2cell(all_unique_dates)' num2cell(zeros(numel(all_unique_dates),1))];%%//'
%%// Get all the dates for the first 36 rows in sorted cell array
dates = [];
for k1=1:size(sorted_cell,2)
dates = [dates reshape(cell2mat(sorted_cell{1,k1}(1:36,4,:)),1,[])];
end
%%// Get unique dates and their counts
unique_dates = unique(dates);
count = histc(dates, unique_dates);
%%// As output create a cell array with the first column as dates
%%// and the second column as the counts
out = [num2cell(unique_dates)' num2cell(count)']
%%// Get all the dates and the corresponding counts.
%%// Thus many would still have counts as zeros.
all_out(ismember(all_unique_dates,unique_dates),:)=out;
关于matlab - 计算前 36 行中某项出现的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22771165/