Problem with accumarray and constructing an array with accumulation
显示 更早的评论
for k=1:24
n =24;
for jj = numel(n):-1:1
cd = circshift(out2hourly{1}, [-(k-1) 0]);
n1 = ceil((1:size(cd,1))'/n(jj));
out{k} = [cd(1:n(jj):end,1), accumarray(n1,cd(:,2),[],@max),...
accumarray(n1,cd(:,3),[],@min),cd(24:n(jj):end,4)];
end
end
Suppose the formula above. Out2hourly is a cell array that contains a matrix with 4 columns and 4000-5000 rows. I want to construct an array with accumulation meaning every 24 rows are summarized to one. The first column has the first value, the second column the maximum value of the 24 rows, the third column has the minimum value of the 24 rows and the last column contains the very last value of the 24 chain. The problem is that the last column will be x-1 rows. The rows of the columns 1-3 have x rows. Therefore I get the following error message:
Error using horzcat
Dimensions of arrays being concatenated are not consistent
I can solve this issue by removing the last row of the first three columns. Therefore I have rewritten the file as below but somehow it doesnt work and I get another error message
out{k} = [cd(1:n(jj):end-1,1), accumarray(n1,cd(1:end-1,2),[],@max),...
accumarray(n1,cd(1:end-1,3),[],@min),cd(24:n(jj):end,4)];
Does anyone haven an idea how to resolve this?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!