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!