I would like to use implied loop for reshape, but got the error message.

Dear all, I would like to reduce computational time, so tried to use implied loop as following:
BD0 = [330 350];
P_interp = interpn(x,y,reshape(squeeze(isen(1:xn,1:yn,:,1:tn)),1,zn),t,reshape(squeeze(isob(1:xn,1:yn,:,1:zn)),1,zn),x,y,BD0',t);
The x and y consist of longitudes and latitudes respectively, and t the time steps. I want to interpolate two more isob values with respect to isen every third dimension according to BD0, but got the error message: Error using reshape To RESHAPE the number of elements must not change. What should I do? Any help would be appreciated.
Sincerely, Charles Tai

 Accepted Answer

For isen you have 1:tn as one of the index ranges ... don't know if that is a typo or if it should have been 1:zn. (Or maybe the other index range of 1:zn should have been 1:tn)
If you want to reshape results as a row vector and not worry about calculating the size needed for that 2nd index, you can use [] for the index instead of the zn you are currently using.

1 Comment

Thanks for your help! Yes, the typo was the latter you mentioned, and the error message has been gone after replacing the index with []. Unfortunately, another problem about monotonically increasing grid vectors for interpn just popped up. Got to fix it. Anyway, thanks again.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!