how add characters to sequence?

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

huda nawaf
huda nawaf 2012년 2월 27일
I will write the sequence clearly
'qwe hj l'

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 2월 27일

0 개 추천

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

댓글 수: 2

huda nawaf
huda nawaf 2012년 2월 27일
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)==' '
z(i)='-'
end
end
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
Andrei Bobrov 2012년 2월 27일
regexp('qwe hj l',' ')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2012년 2월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by