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.

Answers (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 Comment

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

Sign in to comment.

Categories

Tags

No tags entered yet.

Asked:

on 11 Jun 2013

Community Treasure Hunt

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

Start Hunting!