how to write if statement into for loop?

Hi all,
I have scattered data and I want to put them together and exclude the other which is not locate along the main axis, the statement of excluded data is
Longitude>43
and the loop is
for i=1:24
t_interp(:,i)=interp1(z(~isnan(z(:,i)),i),t(~isnan(t(:,i)),i),depth);
s_interp(:,i)=interp1(z(~isnan(z(:,i)),i),sal(~isnan(t(:,i)),i),depth);
end
i cant understand how to write it into the loop, I'm appreciate anyone can help me sorry for my bad English thank you in advance

댓글 수: 3

Star Strider
Star Strider 2014년 5월 24일
It looks as though you just did write it in a loop.
  • What is it not doing that it should?
  • What is it doing that it should not?
  • Do the interp1 statements work outside of the loop?
dpb
dpb 2014년 5월 24일
Think he means to how include the condition, SS...
@lina, what is the variable for Longitude? Need more info...
lina
lina 2014년 5월 24일
the code is for reading data from xls file, Longitude is exists in the file which include 24 stations between 30-45 longitudes the one I dont need it in loop is that >43 which equal to station 4 (by using x=find(Longitude>43) ans=4)
so i need to replace the station 4 values to nan (its also have some nan elements) to interpolate 23 station values
what should i do?

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

 채택된 답변

dpb
dpb 2014년 5월 24일

1 개 추천

Need storage arrangement to be precise, but if you have vectors of same length where Longitude is given for each element, then simply
z(Long>43)=nan;
will do the trick. Or, you could simply select the values to operate on and ignore the rest...
zprime=z(Long<43);
If z is a 2D array will need the (:) operator for the alternate dimension to pick up all rows or columns depending on whether the selected index is column or row, respectively.
Look up "logical addressing" in the documentation -- it's a key element of Matlab syntax and utilization.

댓글 수: 2

lina
lina 2014년 5월 24일
ok thank you
dpb
dpb 2014년 5월 24일
So did that solve the problem? If so, how about "Accepting" the answer; if not, show the actual storage scheme.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2014년 5월 24일

댓글:

dpb
2014년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by