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:
character array from cell

Subject: character array from cell

From: mohammad movassat

Date: 3 Jul, 2009 20:45:03

Message: 1 of 6

Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements.

ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes. any suggestions?

Thank you

Subject: character array from cell

From: Sadik

Date: 3 Jul, 2009 20:55:02

Message: 2 of 6

Hello Mohammad,

If you pad the shorter character array with a sufficient number of blanks, you should be able to have that char array:

G(1,:) = 'x+y+1 '; % I put three blanks at the end.
G(2,:) = '3x-5y+10';

Best.

"mohammad movassat" <movassat@gmail.com> wrote in message <h2lqkf$cqp$1@fred.mathworks.com>...
> Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
> f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements.
>
> ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes. any suggestions?
>
> Thank you

Subject: character array from cell

From: mohammad movassat

Date: 3 Jul, 2009 21:22:01

Message: 3 of 6

"Sadik " <sadik.hava@gmail.com> wrote in message <h2lr76$jch$1@fred.mathworks.com>...
> Hello Mohammad,
>
> If you pad the shorter character array with a sufficient number of blanks, you should be able to have that char array:
>
> G(1,:) = 'x+y+1 '; % I put three blanks at the end.
> G(2,:) = '3x-5y+10';
>
> Best.
>
> "mohammad movassat" <movassat@gmail.com> wrote in message <h2lqkf$cqp$1@fred.mathworks.com>...
> > Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
> > f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements.
> >
> > ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes. any suggestions?
> >
> > Thank you

Thank you, but the issue is that the equations I have are much larger than the equations I showed above. My equations are generated after a couple of algebric manupulations and are vey long. and they are stored in cells. So I need to convert them to char by a command and I can not simply write them as char.

The equations I showed here were samples.

Subject: character array from cell

From: us

Date: 3 Jul, 2009 21:28:01

Message: 4 of 6

"mohammad movassat" <movassat@gmail.com> wrote in message <h2lqkf$cqp$1@fred.mathworks.com>...
> Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
> f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements.
>
> ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes. any suggestions?
>
> Thank you

you've been given solutions to your problem earlier...
tell CSSM what ML version you have...

us

Subject: character array from cell

From: mohammad movassat

Date: 3 Jul, 2009 21:34:01

Message: 5 of 6

"us " <us@neurol.unizh.ch> wrote in message <h2lt51$m7h$1@fred.mathworks.com>...
> "mohammad movassat" <movassat@gmail.com> wrote in message <h2lqkf$cqp$1@fred.mathworks.com>...
> > Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
> > f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements.
> >
> > ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes. any suggestions?
> >
> > Thank you
>
> you've been given solutions to your problem earlier...
> tell CSSM what ML version you have...
>
> us

The solutions did not work, so I'm asking for an alternative.
the version I have is 7.0.4.

mohammad

Subject: character array from cell

From: Sadik

Date: 3 Jul, 2009 21:56:12

Message: 6 of 6

Hi,

You can loop through f like this.

% First determine the longest sequence
maxLength = 0;
for k = 1:length(f)
    currentSeqLength = length(char(f{k}));
    if currentSeqLength > maxLength
        maxLength = currentSeqLength;
    end
end

% Now that we know the maximum length, we can now loop through f and get
% the character array, say charF.

for k = 1:length(f)
    currentSeq = char(f{k});
    charF(k,:) = [currentSeq repmat(' ',1,maxLength-length(currentSeq))];
end

This should now work as you wanted.

Best.

<h2ltg9$ekf$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h2lt51$m7h$1@fred.mathworks.com>...
<h2lqkf$cqp$1@fred.mathworks.com>...
> > > Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
> > > f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements.
> > >
> > > ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes. any suggestions?
> > >
> > > Thank you
> >
> > you've been given solutions to your problem earlier...
> > tell CSSM what ML version you have...
> >
> > us
>
> The solutions did not work, so I'm asking for an alternative.
> the version I have is 7.0.4.
>
> mohammad

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