how to write solve this problem in matlab?

조회 수: 4 (최근 30일)
LOVLIPREET SINGH
LOVLIPREET SINGH 2018년 6월 24일
답변: Walter Roberson 2018년 6월 24일
Dear members I want to write program in matlab in which it takes a sentence(for example: today is sunday) as an input and gives output such that : it should take first word of first letter(example t), then takes first word of second letter(i) after that takes first word of third word(s) and display it as "tis". then for second iteration tiu, third iteration tin and so on. I hope i am able to explain it properly. Thanks in advance.
  댓글 수: 2
Image Analyst
Image Analyst 2018년 6월 24일
Sounds like homework. Is it?
In the meantime, check out strtok() and this link
LOVLIPREET SINGH
LOVLIPREET SINGH 2018년 6월 24일
편집: LOVLIPREET SINGH 2018년 6월 24일
no, this is not at all a homework. I have already graduated from the university. I just started learning MATLAB and trying out different examples to get good at it. i got struck at this problem. would be interesting to know how to tackle this type of problems.

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

답변 (2개)

Star Strider
Star Strider 2018년 6월 24일
This works:
str = 'today is sunday';
words = regexp(str, ' ', 'split');
minlen = min(cellfun(@numel, words));
for k1 = 1:numel(words)
for k2 = 1:minlen
A(k2,k1) = words{k1}(k2);
end
end
Out = A
Out =
2×3 char array
'tis'
'osu'
  댓글 수: 2
LOVLIPREET SINGH
LOVLIPREET SINGH 2018년 6월 24일
편집: LOVLIPREET SINGH 2018년 6월 24일
thanks for replying sir. but this is not the solution i was looking for. I want this output; tis;tiu;tin;tid;tia;tit ois;oiu;oin;oid;oia;oit dis;diu......... ais..... yis..... and so on
Walter Roberson
Walter Roberson 2018년 6월 24일
Where did the tit come from, and what happened to tiy ?

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


Walter Roberson
Walter Roberson 2018년 6월 24일
[P,Q,R] = ndgrid('today','is','sunday')
[reshape(permute(P,[3 1 2]),[],1),reshape(permute(Q,[1 3 2]),[],1),reshape(permute(R,[3 2 1]),[],1)]
or
[P,Q,R] = ndgrid('sunday', 'today','is');
[Q(:),R(:),P(:)]

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by