Why does it say "Subscripted assignment dimension mismatch" ? possibly because of NaN's?
Show older comments
I am interpolating triscattered data onto a regular grid. It works but then stops at t = 10, I don't know why it is doing this!.. I think i had this problem a while back and I managed to sort it but I can't seem to fix it this time. Does anyone know what is wrong? see after code for data dimensions...
weight = cos(REF_lat);
[x,y]=meshgrid(0:1:360,-66:1:66);
x=x(1:end-1,1:end-1); y=y(1:end-1,1:end-1);
load('/work/uo0122/u253082/Mat_Time_Subsampled/STORM_10d_TJJ_ssh_orig_sampling.mat');
s = STORM_10d_TJJ_ssh_orig_sampling;
mask = zeros(size(depth));
mask(find(depth > 0)) = 1;
AM = ones(663,132,360);
Wrep = ones(663,132,360);
for t = 1:size(s,1);
t
tic
a=squeeze(s(t,:,:));
a=a(:);
bad1=find(isnan(a)==1);
a(bad1)=[];
lon=REF_lon(:);
lon(bad1)=[];
lat=REF_lat(:);
lat(bad1)=[];
w = weight(:);
w(bad1)=[];
F1=TriScatteredInterp(lon,lat,a,'natural');
W1=TriScatteredInterp(lon,lat,w,'natural');
a_m=F1(x,y);
AM(t,:,:)=a_m;
W=W1(x,y);
Wrep(t,:,:)=W;
toc
end
weight = 3127 x 254 s = 663 x 3127 x 254 * you can ignore mask
The data I get afterwards looks reasonable too. My biggest suspicion is that it is because it is a timestep that is just NaN's, I tried removing the NaN's but I couldn't seem to do it properly.
Thanks in advance! Michael
8 Comments
Hikaru
on 5 Aug 2014
I think the problem is when you tried to remove NaN inside a for loop.
Geoff Hayes
on 5 Aug 2014
Michael - which line of code is throws the error? Since it is failing only at t equal to 10, then why not step through the code with the debugger?
Either put a breakpoint at the line that throws the error, run the code, and hit continue until you get to the tenth iteration. Or, prior to running the function (or script), run the following command in the Command Window
dbstop if error
Now as you run your function (or script), when an error is encountered the debugger will jump to the line in the function that threw the error.
You can now examine each variable on the left- and right-hand side of the assignment and determine why the subscripted assignment dimension mismatch error is thrown.
An example of this type of error is when an assignment of too little or too much data is being made. For example, suppose we do the following
% create a 4x4 matrix of ones
Z=ones(4,4);
% assign a 1x4 vector to a 1x2 space within the matrix
Z(2,1:2) = ones(1,4);
The above is impossible, and the
Subscripted assignment dimension mismatch.
error is thrown.
Michael
on 5 Aug 2014
Geoff Hayes
on 5 Aug 2014
If F1, lon, lat, and weight are all empty, would that have meant that all of a (or s(10,:,:)) would have been all NaNs? If so, can this still be considered valid data?
Michael
on 5 Aug 2014
Geoff Hayes
on 5 Aug 2014
Why not just skip it
a(bad1) = [];
if isempty(a)
% maybe set all AM data to zero for this t
AM(t,:,:) = 0;
else
lon=REF_lon(:);
lon(bad1)=[];
lat=REF_lat(:);
lat(bad1)=[];
w = weight(:);
w(bad1)=[];
F1=TriScatteredInterp(lon,lat,a,'natural');
W1=TriScatteredInterp(lon,lat,w,'natural');
a_m=F1(x,y);
AM(t,:,:)=a_m;
W=W1(x,y);
Wrep(t,:,:)=W;
end
In the code of your last comment, you seem to be trying to use the NaN data even though it is invalid so am not sure how that would work.
Michael
on 6 Aug 2014
Geoff Hayes
on 6 Aug 2014
No problem, Michael!
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!