Undefine Temperatures with Depth

3 vues (au cours des 30 derniers jours)
nada
nada le 26 Jan 2023
Réponse apportée : dpb le 26 Jan 2023
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
Case 1
Depth<1000 and
Temperature <15 or >40
Case 2
Depth>100 and <300 and
Temperature <15 or >28
Case 3
Depth<300 and
Sal>41.5
Case 4
Depth>300 and <2015 and
Sal <37 or >41.5
Convert the numbers found to 999

Réponse acceptée

dpb
dpb le 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
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
end

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by