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:
conversion

Subject: conversion

From: Jessica

Date: 5 May, 2008 12:25:04

Message: 1 of 5

Hi,
Does anyone know how to convert a series of numbers into a
single value with a colon inbetween the numbers. For
example,

a=5;b=75,c=8;

And I would like to produce:

5:75:8

Subject: conversion

From: Adam Chapman

Date: 5 May, 2008 12:34:22

Message: 2 of 5

On May 5, 1:25=A0pm, "Jessica " <jyorzin...@ucdavis.edu> wrote:
> Hi,
> Does anyone know how to convert a series of numbers into a
> single value with a colon inbetween the numbers. For
> example,
>
> a=3D5;b=3D75,c=3D8;
>
> And I would like to produce:
>
> 5:75:8

Use the 'disp' command, it displays text. You need to convert your
numbers to a text format though, with the 'num2str command. Type 'doc
disp' in you comand line for help.

the code for displaying what you asked is:
disp([num2str(a) ':' num2str(b) ':' num2str(c)]);


Hope this helps,
Adam

Subject: conversion

From: Lorenzo Guerrasio

Date: 5 May, 2008 12:37:03

Message: 3 of 5

It depends on what you need to do, but you may use a cell
format and the command num2cell.

"Jessica " <jyorzinski@ucdavis.edu> wrote in message <fvmub0
$rfg$1@fred.mathworks.com>...
> Hi,
> Does anyone know how to convert a series of numbers into
a
> single value with a colon inbetween the numbers. For
> example,
>
> a=5;b=75,c=8;
>
> And I would like to produce:
>
> 5:75:8

Subject: conversion

From: Jos

Date: 5 May, 2008 13:08:05

Message: 4 of 5

"Jessica " <jyorzinski@ucdavis.edu> wrote in message
<fvmub0$rfg$1@fred.mathworks.com>...
> Hi,
> Does anyone know how to convert a series of numbers into a
> single value with a colon inbetween the numbers. For
> example,
>
> a=5;b=75,c=8;
>
> And I would like to produce:
>
> 5:75:8

What do you mean by "single value"? A string (=character
array) used for display purposes? If so,

sprintf('%d:%d:%d',a,b,c)

will do.

Also note that in matlab the command A:B:C means a list of
numbers running from A to C with steps B

hth
Jos

Subject: conversion

From: Roger Stafford

Date: 5 May, 2008 14:54:03

Message: 5 of 5

"Jessica " <jyorzinski@ucdavis.edu> wrote in message <fvmub0$rfg
$1@fred.mathworks.com>...
> Hi,
> Does anyone know how to convert a series of numbers into a
> single value with a colon inbetween the numbers. For
> example,
>
> a=5;b=75,c=8;
>
> And I would like to produce:
>
> 5:75:8
---------
  If I understand you correctly, you can only do that if your series is an
arithmetic progression - that is, if all the successive differences are equal
(within rounding error.) If x is a row vector with such a sequence (with at
least two elements,) then you can use

 y = x(1):x(2)-x(1):x(end);

in place of x. However, note that rounding errors can cause very small
differences between y and x.

  Is this what you are asking for? Your example is rather puzzling since it
consists of the single scalar 5. The next value after 5 would be 5+75=80
which is beyond 8 and therefore not in the series.

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