Why does it say "Subscripted assignment dimension mismatch" ? possibly because of NaN's?
1 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Geoff Hayes
2014-8-6
For the case of t being equal to ten, it was found that the line of code that was generating the Subscripted assignment dimension mismatch error was
a_m=F1(x,y);
The variables F1, lon, lat, and weight were all empty due to the all elements in the s(t,:,:) matrix being set to NaN.
A solution was to address this in the code as follows - if it was found that the a matrix was empty (after the removal of NaNs) then do nothing (or set the output to be all zeros) and just continue with the next iteration of the for loop
a=squeeze(s(t,:,:));
a=a(:);
bad1=find(isnan(a)==1);
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
2 个评论
Geoff Hayes
2014-8-6
编辑:Geoff Hayes
2014-8-6
Good that you have it working. Am just unsure of one thing: I thought that the error was being generated from the previous line
a_m=F1(x,y);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!