Got Questions? Get Answers.
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:
How to convert nonuniform cell to uniform matrix?

Subject: How to convert nonuniform cell to uniform matrix?

From: Greg Heath

Date: 1 Apr, 2013 00:20:06

Message: 1 of 4

I have a 10x15 cell named stopcrit0 with character elements
of different lengths:

'Validation stop.'
'Minimum gradient reached.'
'Performance goal met.'

I would like to replace it with a corresponding 10x15 character
matrix named stopcrit with elements of length 7:

'valstop'
'mingrad'
'perfmet'

The majority of the elements will be 'Valstop.'. Therefore,
my plan was to initialize stopcrit with 'valstop' and then loop
through stopcrit0 elementwise to replace 'valstop' in stopcrit
where indicated.

Or is it better to make the changes to the cell and then convert
it to a matrix?

What is the best way to do this? I would appreciate code.

TIA

Greg

Subject: How to convert nonuniform cell to uniform matrix?

From: Bruno Luong

Date: 1 Apr, 2013 05:28:18

Message: 2 of 4

% Mapping
longstr={'Validation stop.' 'Minimum gradient reached.' 'Performance goal met.'};
shortstr={'valstop' 'mingrad' 'perfmet'};

% Random data
stopcrit0 = longstr(ceil(3*rand(10,15)));

% Simple indexing:
[~, loc] = ismember(stopcrit0, longstr);
stopcrit = shortstr(loc)
% Let you rearrange stopcrit as "char matrix" (I'm not sure what is it).

% Bruno

Subject: How to convert nonuniform cell to uniform matrix?

From: Bruno Luong

Date: 1 Apr, 2013 05:39:22

Message: 3 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> % Let you rearrange stopcrit as "char matrix" (I'm not sure what is it).

Just a guess, here is a char array:

s = reshape(cat(3,stopcrit{:}),[1 7 size(stopcrit)])

% Bruno

Subject: How to convert nonuniform cell to uniform matrix?

From: Greg Heath

Date: 1 Apr, 2013 11:30:08

Message: 4 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kjb6ia$dn9$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> > % Let you rearrange stopcrit as "char matrix" (I'm not sure what is it).
>
> Just a guess, here is a char array:
>
> s = reshape(cat(3,stopcrit{:}),[1 7 size(stopcrit)])
>
> % Bruno

Thanks.

Don't understand them yet. So I'll just say

Thanks.

Greg

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