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

how add characters to sequence?

Asked by huda nawaf on 27 Feb 2012

hi, I have this seq. for example qwe hj l

what I need is adding gaps in spaces of this sequence, such qwe---hj--l

I want code do that

many thanks in advance

1 Comment

huda nawaf on 27 Feb 2012

I will write the sequence clearly

'qwe hj l'

huda nawaf



No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 27 Feb 2012
out = regexprep('qwe hj l',' ','   ')


a = regexp('qwe hj l',' ','split');
out = cell2mat(cellfun(@(x)[x,blanks(length(x))],a,'un',0))


huda nawaf on 27 Feb 2012

thanks ,
but the result is not what I need
when use regexprep, I got
qwe hj l

i have long sequences, this is just example , I need something more general.
i.e I need code palce '-' in any space find it.
I can not get the index of spaces, this is my problem.
ex. z='qwe hj l';
for i=1:length(j)
if z(i)==' '
this is code did not get the spaces, also when use if z(i)==[].
So, how I can get the index of spaces?
i tried use if

Andrei Bobrov on 27 Feb 2012

regexp('qwe hj l',' ')

Andrei Bobrov

Contact us