Find function - how to use or index to a return when "Find" cannot find anything.
71 views (last 30 days)
Show older comments
We have some sophisticated isotope hardware coupled to the most useless software imaginable. I have written some code to identify a series of retention times, fill out a new column of RT's for cross matching and also fill in the compound names for identification. Where chromatographic peaks are too close to separate by retention time alone I have added the facility to look for the largest peak size or first or last on a doublet.
But I want the code to show 'not found' values if the FIND function can't find a value at all. Sometimes a peak is missing. This way, all my data files will be the same length.
In the portion of code here, it all works fine until you change the first IF statement to elseif and insert the new IF statement above it that seeks to identify when FIND doesn't find. I have tried a few things including ISEMPTY in the first IF statement. But while this works fine in the command window, coupled inside the IF statement it won't work.
I need some way to identify a missing value for RTidx. Anyone?
start = 1;
finish = loc(1);
R = rt(start:finish);
for C = [1:10, 13, 14, 15, 17:18, 20:22];
RTidx = find(R >= S(C) & R <= E(C));
if RTidx = [ ];
name(RTidx) = not_found(C);
elseif (length(RTidx)>1);
[junk, i] = max(mv(RTidx));
rt_fill(RTidx(i)) = rt(RTidx(i));
name(RTidx(i)) = amino_list(C);
else
rt_fill(RTidx) = rt(RTidx);
name(RTidx) = amino_list(C);
end;
RT_FILL(LISTidx) = rt_fill;
NAME_FILL(LISTidx) = name;
end
1 Comment
bym
on 26 Oct 2011
I don't know if it makes a difference, but it looks like you have [ ](a space in the empty matrix). can you try [] (no space)
Accepted Answer
Walter Roberson
on 26 Oct 2011
Your line
if RTidx = [ ];
would attempt to assign the empty array to RTidx, which is not something you can do in an "if" statement.
if isempty(RTidx)
is the appropriate test.
You might want to cross-check with size(RTidx) and class(RTidx) to see what is happening.
More Answers (1)
the cyclist
on 26 Oct 2011
I would think the best way to do this would be with the isempty() command, but you don't show what you tried there.
However, I also notice that you have used
if RTidx = []
rather than
if RTidx == []
You need the doubled equal sign for checking equality. A single equal sign is for assignment.
See Also
Categories
Find more on Entering Commands 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!