How to correct Reshape error
1 view (last 30 days)
Show older comments
I'm new to MATLAB, thanks in advance.
I'm attempting to reshape several fields from hourly to daily values (2136 by 1) and should get 89 days of data. Using the code below, I receive the following error message...
Error using reshape
Size arguments must be real integers.
Is there an obvious solution I'm missing?
figure (2)
runoff_daily=(nanmean(reshape(GridOut.runoff_hourly,24,(datasize/24))))';
alldebmelt_daily=(nanmean(reshape(GridOut.alldebmelt_hourly,24,(datasize/24))))';
alldirtymelt_daily=(nanmean(reshape(GridOut.alldirtymelt_hourly,24,(datasize/24))))';
allcleanmelt_daily=(nanmean(reshape(GridOut.allcleanmelt_hourly,24,(datasize/24))))';
allsnowmelt_daily=(nanmean(reshape(GridOut.allsnowmelt_hourly,24,(datasize/24))))';
0 Comments
Answers (1)
dpb
on 7 Oct 2017
"Is there an obvious solution I'm missing?"
Not necessarily so obvious solution, but an apparent problem...
reshape(GridOut.runoff_hourly,24,(datasize/24))
unless mod(datasize,24) == 0, then there will be a remainder in the second argument to reshape given the message is what it is, that's pretty clearly the issue. You should use the [] syntax in cases like this any way, but that won't solve the problem of mismatched data sizes.
reshape(GridOut.runoff_hourly,24,[]) % let Matlab determine second dimension...
About all you can do in such a case is to use only the
Ndays=fix(length(runoff_hourly)/24);
as the number of elements such as
reshape(GridOut.runoff_hourly(1:Ndays),24,(datasize/24))
and then treat the remaining partial day values independently or ignore them as not being full 24-hr day. Of course, you'll want to ensure the first entry corresponds to the first element for the day; otherwise you'll need to locate it and the last element of the last full day.
0 Comments
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!