Issues in For loop
Show older comments
Hi All,
I ma facing issues while reading data and saving in to desired fashion. Here is an example, I need to save the temperature and salinity from a large dataset in every 120th raw for which i wrote the code as shown below.....is there any error? as I am recieving the entire data filed instead of every 120th one....
for i=1:38976;
if(j==120);
if(temp(i)> 0 && temp(i) < 30 );
temp(i)=temp(i) ;
else
temp(i)=NaN;
end
if(sal(i)> 30 && sal(i)< 42);
sal(i)=sal(i);
else
sal(i)=NaN;
end
j=1;
else
j=j+1;
end
end
Accepted Answer
More Answers (1)
Alan Stevens
on 23 Jun 2021
0 votes
Have you intialised j (i.e. set j = 1;) before going into the for i = 1:38976 loop?
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!