problem with undefined variable in for loop.

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.

답변 (1개)

Walter Roberson
Walter Roberson 2014년 4월 2일

0 개 추천

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

lina
lina 2014년 4월 2일
ok, i got the point
the variable is sal and p, in the second if statement، the Matrix appears empty are no values, such as those in t and z those are define in first if statement.
Thank very much for your help Mr. Walter
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
so i don't need to use it here even if i write
else exist('Pressure','var');
because it doesn't show me any values is it right?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2014년 4월 2일

댓글:

2014년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by