From: sez on
Hi all,
I am trying to store data in one variable throughout my whole time
period, but my code runs through a loop, so the data keeps getting
replaced every loop. I want the data for when the sum(test)>=1 only,
and the variable I'm trying to save is lon_spath. I've tried many
different ways but can't figure it out. Right now the loop works but
like I said, just replaces lon_spath every loop. Here is my code...

for iday = 1:length(itime)
lat=lat_ke(:,iday);
lon=lon_ke(:,iday);

for icheck = 1:length(lon_new)-1
iwant = find(lon >= lon_new(icheck) & lon < lon_new(icheck
+1));

if length(iwant) == 0
lat_new(icheck) = NaN;
test(icheck) = 0;
elseif range(lat(iwant)) < 0.1;
lat_new(icheck) = mean(lat(iwant));
test(icheck) = 0;

else
lat_new(icheck) = min(lat(iwant));
test(icheck) = 1;

end
end


if sum(test) >= 1

if sum(abs(diff(lat_new)) > .7)
dtxt = to_date(1998, itime(iday));
count = count+1;
lon_spath = lon_mid(test==1);
lon_spath = lon_spath +1;
bb= num2str(lon_spath);

% fprintf(fid,'%d %s %s \n',count, dtxt, bb);

isSpath(iday) = 1;

end
end

I tried doing:
alldata(:,iday) = lon_spath but dimensions don't agree. I've tried
lon_spath(iday) = lon_mid(test==1). and things similar but I'm
stuck!
If anyone has ideas, I'd appreciate it. Thanks in advance!
From: us on
sez <szamorski1(a)gmail.com> wrote in message <bc5a8a25-4e06-4efd-ae98-b41ab4a0bc2b(a)r27g2000yqb.googlegroups.com>...
> Hi all,
> I am trying to store data in one variable throughout my whole time
> period, but my code runs through a loop, so the data keeps getting
> replaced every loop. I want the data for when the sum(test)>=1 only,
> and the variable I'm trying to save is lon_spath.

one good example to use one of the solutions shown here at

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

us