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:
Replacing Numeric Vector With Strings

Subject: Replacing Numeric Vector With Strings

From: james bejon

Date: 31 Mar, 2010 12:11:02

Message: 1 of 3

Dear All,

Judging by some of the response I've had/read on here, it seems I'm using far too many loops in my code. I've addressed a fair bit of this, but I'm wondering if there's a nice way of turning

[1, 2, 2, 2, 3, 2]

into

['Bob', 'Jim', 'Jim', 'Jim', 'John', 'Jim']

given, of course, a (sorted) cell: {'Bob', 'Jim', 'John'}?

Subject: Replacing Numeric Vector With Strings

From: Sadik

Date: 31 Mar, 2010 12:24:04

Message: 2 of 3

Hi James,

A = [1, 2, 2, 2, 3, 2];
names = {'Bob', 'Jim', 'John'};

so

names(A)

is going to give you the cell array you are looking for.

Best.

Subject: Replacing Numeric Vector With Strings

From: james bejon

Date: 31 Mar, 2010 18:19:20

Message: 3 of 3

Of course! Thanks very much.

Tags for 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