I am trying to mask values in a matrix that are out of a specified range and trying to make a new matrix from the values after the values out of the range have been masked.
53 views (last 30 days)
Show older comments
I am trying to mask values in a matrix that were calculated using values of theta. I am trying to mask values that are less that 20 deg. From the values that have not been masked I am trying to make a new matrix
i.e.
Gamma - matrix before mask values
gamma - new matrix after values have been masked
gamma = (somefunction to mask Gamma)
0 Comments
Accepted Answer
Voss
on 18 Feb 2022
Edited: Voss
on 18 Feb 2022
It's not entirely clear exactly what you have in mind, but one or more of these options should cover it. If not, please explain further.
% some theta values:
theta = [0:4 5:5:30]
% calculate Gamma using some function of theta:
Gamma = theta.^2
% take the values of Gamma greater than or equal to 20:
gamma = Gamma(Gamma >= 20)
% or take the values of Gamma where theta was greater than or equal to 20:
gamma = Gamma(theta >= 20)
% or set the values of Gamma less than 20 to NaN
gamma = Gamma;
gamma(Gamma < 20) = NaN
% or set the values of Gamma less than 20 to 0
gamma = Gamma;
gamma(Gamma < 20) = 0
% or set the values of Gamma where theta was less than 20 to NaN
gamma = Gamma;
gamma(theta < 20) = NaN
% or set the values of Gamma where theta was less than 20 to 0
gamma = Gamma;
gamma(theta < 20) = 0
0 Comments
More Answers (1)
DGM
on 18 Feb 2022
Edited: DGM
on 18 Feb 2022
This is all still terribly nonspecific. "Masking" may be generally read as "selecting". What is to happen to the undesired elements? Are they set to zero? To NaN? ... or do the workflow allow the extraction of the desired elements alone, perhaps as a vector?
Consider the array of angles:
A = reshape(round(linspace(0,40,25)),5,5)
mask = A<20
% set masked values to 0
B = A;
B(mask) = 0
% set masked values to NaN
C = A;
C(mask) = NaN
% extract vector of unmasked values
D = A(~mask)
0 Comments
See Also
Categories
Find more on Gamma Functions 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!