- 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?
how to write if statement into for loop?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2014-5-24
Think he means to how include the condition, SS...
@lina, what is the variable for Longitude? Need more info...
采纳的回答
dpb
2014-5-24
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 个评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!