Why does it say "Subscripted assignment dimension mismatch" ? possibly because of NaN's?

1 visualización (últimos 30 días)
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 comentarios

Iniciar sesión para comentar.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 6 de Ag. de 2014
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 comentarios
Michael
Michael el 6 de Ag. de 2014
thanks, I ended up using this command in the world, but in a musch simpler way within the loop:
if isempty(a_m) == 0;
AM(t,:,:)=a_m;
end
Geoff Hayes
Geoff Hayes el 6 de Ag. de 2014
Editada: Geoff Hayes el 6 de Ag. de 2014
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);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by