How do I fix error: Index exceeds matrix dimensions?
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
I want to make a loop where I calculate the mean of my 35040x12datamatrix for every 24 datapoint, but I get an error: Error using dataset/subsref (line 616) Index exceeds matrix dimensions.
for i=1:24:35040
Xday(icount,:)=mean(A.data(i:24*i,:));
icount=icount+1;
end
What am I doing wrong? Thanks
0 个评论
回答(2 个)
James Tursa
2016-2-3
编辑:James Tursa
2016-2-3
Try this:
for i=1:24:35040
Xday(icount,:)=mean(A.data(i:(i+23),:)); % <-- Changed 24*i to i+23
icount=icount+1;
end
Or a vectorized way:
Xday = reshape(mean(reshape(A.data,24,[])),1460,[]);
0 个评论
Lilja Dahl
2016-2-3
0 个投票
2 个评论
James Tursa
2016-2-3
编辑:James Tursa
2016-2-3
For the loop, did you preallocate Xday? E.g., Xday = zeros(1460,12). And did you initialize icount = 1?
Lilja Dahl
2016-2-12
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!