Undefine Temperatures with Depth
1 view (last 30 days)
Show older comments
Hi and thanks in advance.
I have data for depth,temperatures and salinity.
I want to find temperature with depth as well as salinity.the condation is
Temperature <15 or >40
Depth>100 and <300 and
Temperature <15 or >28
Depth>300 and <2015 and
Sal <37 or >41.5
Convert the numbers found to 999
dpb on 26 Jan 2023
See <Logical Array Indexing> and use the MATLAB <missing> instead of some magic number for missing values.
An example for one of your above cases of syntax would be
data(Depth<1000 & Temperature<15 | Temperature>40,:)=missing;
will set all variables in the data array of those conditions. This, unfortunately, will also lose the independent variables as well as whatever observed variables there are; the Q? is is that what you really intend? If the point is to subset the data for analysis only of the remaining conditions, it might be as well to simply remove those rows entirely for the purpose of analysis, but not actually remove them physically nor mark them permanently but just address those of interest for analysis dynamically.
In that case, negate the sense of the test and use something like--
dataCase1=data(~(Depth<1000 & Temperature<15 | Temperature>40),:);
and then analyze the resulting dataset. Using a generic name for the LHS variable instead of the example named for illustration will be more generic coding rather than making names for every individual case.
The above can be written more succinctly at the command line with the use of my "syntactic sugar" utility routine iswithin that hides the compound test clutter from the top level code...
dataAnalysis=data(~(Depth<1000 & iswithin(Temperature,15,40)),:);
where iswithin is
% returns T for values within range of input
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
More Answers (0)
Find more on Structures 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!