Thread Subject: How to read a specific number

Subject: How to read a specific number

From: Prashant Sandhi

Date: 3 Jan, 2012 10:27:08

Message: 1 of 6

Dear friends,

          Let's say I have 21 and 41 then I want to read only '2' from the first number and then I want to read '4' from the second number. How is it possible in matlab and as well in simulink to do such operation?

          In simulink we have to use two constant block's were I can write 21 & 41 respectively in each block. But how can I read the desired number from these blocks. Is there any other way in simulink?

          In short I want to read any give specific number from a given number.
Ex: In 3698 I would like to read out only 6.

Any suggestion will be very helpful !

Prashant

Subject: How to read a specific number

From: Prashant Sandhi

Date: 3 Jan, 2012 10:34:08

Message: 2 of 6

"Prashant Sandhi" wrote in message <jdul5s$5dg$1@newscl01ah.mathworks.com>...
> Dear friends,
>
> Let's say I have 21 and 41 then I want to read only '2' from the first number and then I want to read '4' from the second number. How is it possible in matlab and as well in simulink to do such operation?
>
> In simulink we have to use two constant block's were I can write 21 & 41 respectively in each block. But how can I read the desired number from these blocks. Is there any other way in simulink?
>
> In short I want to read any give specific number from a given number.
> Ex: In 3698 I would like to read out only 6.
>
> Any suggestion will be very helpful !
>
> Prashant

Apart from reading a specific number I have another question.
Imagine if there is a number 16, 7 , 10 then I want to write down these numbers as single number 16710. How can I do this in Matlab 6 also in simulink.

Thanking you!

Prashant

Subject: How to read a specific number

From: dpb

Date: 3 Jan, 2012 15:45:22

Message: 3 of 6

On 1/3/2012 4:34 AM, Prashant Sandhi wrote:
> "Prashant Sandhi" wrote in message
> <jdul5s$5dg$1@newscl01ah.mathworks.com>...
>> Dear friends,
>>
>> Let's say I have 21 and 41 then I want to read only '2' from the first
>> number and then I want to read '4' from the second number. How is it
>> possible in matlab and as well in simulink to do such operation?

Simulink-specific you'll have to find somebody else

In Matlab easies

...

>> In short I want to read any give specific number from a given number.
>> Ex: In 3698 I would like to read out only 6.
...

Simplest probably is to convert to string and select the desired digit
position...say it's the 2nd as above...

s=sprintf('%d',x);
n=str2num(s(2));

Wrap in a function and pass the desired position and value; return the
answer...

> Apart from reading a specific number I have another question.
> Imagine if there is a number 16, 7 , 10 then I want to write down these
> numbers as single number 16710. How can I do this in Matlab 6 also in
> simulink.
...

Again, use the rtl i/o to ease the problem...

n=[16,7,10];
v=num2str(sprintf('%d',n));

And again, what would be a Simulink-specific solution I've no
clew...never even seen the product.

--

Subject: How to read a specific number

From: Phil Goddard

Date: 3 Jan, 2012 23:42:08

Message: 4 of 6

Assuming you only want it for simulation then the easiest approach will be an (Embedded) MATLAB Function block that uses almost identical code to the way it would be done in MATLAB (with the appropriate functions defined as eml.extrinsic).

If you need it for code generation then you'll need to figure out how to do it in C and then write a C-mex S-Function.

Phil.

Subject: How to read a specific number

From: Prashant Sandhi

Date: 4 Jan, 2012 09:15:08

Message: 5 of 6

"Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <je03og$g65$1@newscl01ah.mathworks.com>...
> Assuming you only want it for simulation then the easiest approach will be an (Embedded) MATLAB Function block that uses almost identical code to the way it would be done in MATLAB (with the appropriate functions defined as eml.extrinsic).
>
> If you need it for code generation then you'll need to figure out how to do it in C and then write a C-mex S-Function.
>
> Phil.

Thank you Phil & dpb for your replies.

I have found that the approach to my problem has to be done by considering more points. such as, if I have two number 21 & 23 that means both have two digits (units & tens places) but if I have unbalanced digits of numbers such as 378967 & 68 then first I have to find the max number of digits i.e. in this case it will be 6 digits so that means 68 has to be treated as 000068. That means when I have two numbers x & y, first I have to make them as same number of digits as 378967 & 000068. This will be my starting point.
I have to first find out How I can do this in Matlab & as well in Simulink.

Subject: How to read a specific number

From: Steven_Lord

Date: 4 Jan, 2012 14:23:59

Message: 6 of 6



"Prashant Sandhi" <sandhi.prashant@gmail.com> wrote in message
news:je15as$l4u$1@newscl01ah.mathworks.com...
> "Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in
> message <je03og$g65$1@newscl01ah.mathworks.com>...
>> Assuming you only want it for simulation then the easiest approach will
>> be an (Embedded) MATLAB Function block that uses almost identical code to
>> the way it would be done in MATLAB (with the appropriate functions
>> defined as eml.extrinsic).
>>
>> If you need it for code generation then you'll need to figure out how to
>> do it in C and then write a C-mex S-Function.
>>
>> Phil.
>
> Thank you Phil & dpb for your replies.
>
> I have found that the approach to my problem has to be done by considering
> more points. such as, if I have two number 21 & 23 that means both have
> two digits (units & tens places) but if I have unbalanced digits of
> numbers such as 378967 & 68 then first I have to find the max number of
> digits i.e. in this case it will be 6 digits so that means 68 has to be
> treated as 000068. That means when I have two numbers x & y, first I have
> to make them as same number of digits as 378967 & 000068. This will be my
> starting point.
> I have to first find out How I can do this in Matlab & as well in
> Simulink.

Look at the LOG10 and MOD or REM functions.

n = 68;
mod(n, 10)
(n-mod(n, 10))/10

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com