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

implied loopinginterpnreshape

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

Best 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.