Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
position-inverse of a whole number

Subject: position-inverse of a whole number

From: Candide Voltaire

Date: 9 Aug, 2011 12:15:06

Message: 1 of 8

Does Matlab have a function to determine the "position-inverse" of a
whole number?
e.g. 123-->321, 7012-->2107...
If such a function does not exist can anyone here give suggestions on
how to realise this?

regards,
Candide

Subject: position-inverse of a whole number

From: dpb

Date: 9 Aug, 2011 12:55:31

Message: 2 of 8

On 8/9/2011 7:15 AM, Candide Voltaire wrote:
> Does Matlab have a function to determine the "position-inverse" of a
> whole number?
> e.g. 123-->321, 7012-->2107...
> If such a function does not exist can anyone here give suggestions on
> how to realise this?
...

One possible way...

 >> n = 123;
 >> r=str2num(fliplr(num2str(n)))
r =
    321
 >>

--

Subject: position-inverse of a whole number

From: Roger Stafford

Date: 10 Aug, 2011 03:04:11

Message: 3 of 8

Candide Voltaire <candideguevara@gmail.com> wrote in message <f98c03e5-178d-4b43-892e-f50d47e43fda@e35g2000yqc.googlegroups.com>...
> Does Matlab have a function to determine the "position-inverse" of a
> whole number?
> e.g. 123-->321, 7012-->2107...
> If such a function does not exist can anyone here give suggestions on
> how to realise this?
>
> regards,
> Candide
- - - - - - - - - -
  Your use of the term "inverse" would seem to imply some kind of one-to-one (bijective) mapping. Unfortunately that doesn't appear to be the case with what you describe. For example, all the following numbers would apparently map into the same number: 123, 1230, 12300, 123000, ..., namely three hundred twenty one. If that is not so, what would you have 1230, 12300, 123000, ... map into?

Roger Stafford

Subject: position-inverse of a whole number

From: Candide Voltaire

Date: 10 Aug, 2011 09:14:02

Message: 4 of 8

On 9 aug, 14:55, dpb <n...@non.net> wrote:
> On 8/9/2011 7:15 AM, Candide Voltaire wrote:> Does Matlab have a function to determine the "position-inverse" of a
> > whole number?
> > e.g. 123-->321, 7012-->2107...
> > If such a function does not exist can anyone here give suggestions on
> > how to realise this?
>
> ...
>
> One possible way...
>
>  >> n = 123;
>  >> r=str2num(fliplr(num2str(n)))
> r =
>     321
>  >>
>
> --

thanks this works like a charm, to make it work on a number array I
just had to add one fliplr instruction
n=1:1:50
 r=fliplr(str2num(fliplr(num2str(n))))

Subject: position-inverse of a whole number

From: Candide Voltaire

Date: 10 Aug, 2011 09:14:46

Message: 5 of 8

On 10 aug, 05:04, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> Candide Voltaire <candideguev...@gmail.com> wrote in message <f98c03e5-178d-4b43-892e-f50d47e43...@e35g2000yqc.googlegroups.com>...
> > Does Matlab have a function to determine the "position-inverse" of a
> > whole number?
> > e.g. 123-->321, 7012-->2107...
> > If such a function does not exist can anyone here give suggestions on
> > how to realise this?
>
> > regards,
> > Candide
>
> - - - - - - - - - -
>   Your use of the term "inverse" would seem to imply some kind of one-to-one (bijective) mapping.  Unfortunately that doesn't appear to be the case with what you describe.  For example, all the following numbers would apparently map into the same number: 123, 1230, 12300, 123000, ..., namely three hundred twenty one.  If that is not so, what would you have 1230, 12300, 123000, ... map into?
>
> Roger Stafford
What name do you think would be more appropiate?

regards,
Candide

Subject: position-inverse of a whole number

From: dpb

Date: 10 Aug, 2011 13:21:58

Message: 6 of 8

On 8/10/2011 4:14 AM, Candide Voltaire wrote:
> On 10 aug, 05:04, "Roger Stafford"
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
>> Candide Voltaire<candideguev...@gmail.com> wrote in...
>>> Does Matlab have a function to determine the "position-inverse" of a
>>> whole number?
>>> e.g. 123-->321, 7012-->2107...
...
>> Your use of the term "inverse" would seem to imply some kind of
>> one-to-one (bijective) mapping. Unfortunately that doesn't appear to be
>> the case with what you describe. For example, all the following numbers
>> would apparently map into the same number: 123, 1230, 12300, 123000,
>> ..., namely three hundred twenty one. If that is not so, what would you
>> have 1230, 12300, 123000, ... map into?
>>
>> Roger Stafford

> What name do you think would be more approp[r]iate?

...

The "position-inverse" seemed clear enough (at least w/ the example)
altho I suppose "reversed" might be a better choice, who knows?

BTW, to solve the problem (if it is one) Roger posits, the simplest
solution is to retain the reversed digits as the "flipped" string rather
than convert back to numeric.

--

Subject: position-inverse of a whole number

From: Matt J

Date: 10 Aug, 2011 13:45:20

Message: 7 of 8

dpb <none@non.net> wrote in message <j1u0ll$qpq$2@speranza.aioe.org>...
> On 8/10/2011 4:14 AM, Candide Voltaire wrote:
>
> BTW, to solve the problem (if it is one) Roger posits, the simplest
> solution is to retain the reversed digits as the "flipped" string rather
> than convert back to numeric.
======================
 

Another sensible generalization would be to leave trailing zeros unflipped, i.e.,

1230 maps to 3210
12300 maps to 32100

This way, the transform would accomodate not just whole numbers, but fractional ones as well, e.g.

1.23 maps to 3.21

More complicated to code, obviously....

Subject: position-inverse of a whole number

From: Roger Stafford

Date: 10 Aug, 2011 18:01:29

Message: 8 of 8

Candide Voltaire <candideguevara@gmail.com> wrote in message <04cd6592-d9a7-437a-9228-29f22af3cb8c@z7g2000vbp.googlegroups.com>...
> What name do you think would be more appropiate?
- - - - - - - - -
  It is sometimes called "digit reversal". It is an essential part of FFT algorithms when applied to binary numbers where it is called "bit reversal". See:

 http://en.wikipedia.org/wiki/Bit-reversal_permutation
 http://en.wikipedia.org/wiki/Cooley–Tukey_FFT_algorithm
 
Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us