Image analysis program: 'find' not working
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
testnumber=2;
vectortofindtestnumber=[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 19 20
];
checkiftestelementhasduplicatesinthevector=find(testnumber==vectortofindtestnumber);
if(length(checkiftestelementhasduplicatesinthevector)>1)
disp('Found a duplicate'); % Do some steps
end
for '2' my code in my image analysis program is going into if condition and is getting processed.
I feel definitely this is a run-time bug, but any similar experiences any of you can share would be helpful.
Any help would be appreciated.
Thanks in advance
Respuestas (2)
Walter Roberson
el 27 de Ag. de 2013
0 votos
You do not show any "else" after the length check, and your "Do some steps" does not show any action to avoid doing the code that is after the "if". Remember, if you have an "if" then that does not mean skip all the rest of the program if the condition is false: it means that if the condition is false, skip only what is in the "if" block.
5 comentarios
SreeHarish Muppirisetty
el 27 de Ag. de 2013
Editada: Image Analyst
el 27 de Ag. de 2013
Walter Roberson
el 27 de Ag. de 2013
Caution: you have vectortocompare(checkeachlelem) with checkeachlelem being a misspelling.
We do not have your vectortofindtestnumber so we cannot test the code.
What output are you observing?
SreeHarish Muppirisetty
el 27 de Ag. de 2013
Editada: Walter Roberson
el 28 de Ag. de 2013
Walter Roberson
el 28 de Ag. de 2013
When you say "from command line" compared to "while executing the program", what do we need to know about how you are executing the program? Did you write it to a .m file and are giving the name of the .m file? If so then have you checked with "which" to be sure you are executing the correct .m file ? Did you add anything else to that file?
SreeHarish Muppirisetty
el 28 de Ag. de 2013
Image Analyst
el 27 de Ag. de 2013
Editada: Image Analyst
el 27 de Ag. de 2013
Why not simply use ismember:
% Define the large list to search.
vectorToCompare=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
% Define the numbers to look for in the larger list.
testnumber= [2 2 5 42];
[hits, indexes] = ismember(testnumber, vectorToCompare)
if any(hits)
message = sprintf('%d numbers found.', sum(hits));
else
message = sprtinf('No numbers found.');
end
msgbox(message);
P.S. How does this have to do with image analysis?
3 comentarios
SreeHarish Muppirisetty
el 27 de Ag. de 2013
Image Analyst
el 28 de Ag. de 2013
Did it work? It worked for me.
SreeHarish Muppirisetty
el 28 de Ag. de 2013
Editada: Walter Roberson
el 28 de Ag. de 2013
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!