problem with undefined variable in for loop.
1 次查看(过去 30 天)
显示 更早的评论
hi,
I have problem here for undefined variable
for i=1:41
ncload(['wod_00',num2str(cast(i)),'O.nc']);
% pause
[n,m]=size(Temperature);
if lat<20;
(~exist('Pressure'))
t(1:n,i)=Temperature(:);
sal(1:n,i)=Salinity(:);
Z(1:n,i)=z(:);
else lat>20
t(1:n,i)=Temperature(:);
Z(1:n,i)=z(:);
if exist('Salinity', 'var')
sal(1:n,i)=Salinity(:);
else exist('Pressure','var');
p(1:n,i)=Pressure(:);
end
end
end
thank you.
0 个评论
回答(1 个)
Walter Roberson
2014-4-2
Which variable, and at which point?
Note that
(~exist('Pressure'))
tests whether Pressure exists as any of a number of kinds of object, then takes the logical negation of the result, and displays it to the screen, without using it in computation.
Some of your files might have variables defined that others do not. You should be clear'ing variables that are potentially loaded from the file, as otherwise the data from the previous file might be still be in memory.
3 个评论
Walter Roberson
2014-4-2
编辑:Walter Roberson
2014-4-2
Note that
else lat>20
is the same as
else
disp(lat>20)
and
else exist('Pressure','var');
is the same as
else
exist('Pressure','var'); %calculate result and throw it away
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!