How can I find index of nearest value to specific number

Please find attached file I want to find first index of arrays < 5 and then remove them from matrix (I want to filter arrays less than 5). I really appreciate any help.

8 Commenti

The question in your title is different to in the body so I'm not sure which is the one you actually mean, but
doc find
works for the one in the question body, e.g.
find( myArray < 5, 1 );
and for finding the nearest element to some value
[~, idx] = min( abs( myArray - 5 ) );
would find the value closest to 5 in myArray.
I tried your comment, but it is not what I am looking for. If you open file at the top rows of the matrix is the values less than 5 I want to have a new matrix that start with the values greater than 5, whilst the values less than 5 replace with NaN.
The comment below is what I am looking for; thanks
Pnew = reshape(P,[],1);
idx = find(Pnew<5);
Pnew(idx)=NaN;
Looking at your attached data, the matrix is 143-by-417 and the 1st rows contains many >5 values.
Could you tell us more details on the problem you are facing and on what the desired output matrix looks like.
the attached file is the water depth and for further analysis I want to avoid and filter the depth less than 5 m becuse of inaccuracy in measurement by the marine instrument.
function out_put=filter_specific_value(Mymatrix,filter_value)
newmatrix = reshape(Mymatrix,[],1);
[idx] = find(newmatrix<filter_value);
newmatrix(idx)=NaN;
out_put = reshape(newmatrix,size(Mymatrix));
end
I don't see any attachments. Is this question answered?
I deleted I got my answer, I attached again.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by