new to matlab, I am tring to write a peice of code that accepets two premanitars and displys all numbers that have a digit equal to ‘2’ .

This seems like a fairly simple concept but how can i write this so that only number with digits of 2 are displayed. Reading around i found that %c will look for specific characters but i don't understand how to use it. Any help or direction on this matter is apperecated.

Respuestas (1)

%example x
x = [17.5;12.3;132;211;3.1419];
%convert to string
xstr = num2str(x);
%any column has a digit 2
idx = any(xstr=='2',2);
%Extract from x
x(idx)
Welcome to MATLAB and Answers!

1 comentario

thank you for the help. It looks like what i was missing was putting it into a string.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 11 de Jun. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by