how to write solve this problem in matlab?
古いコメントを表示
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
2018 年 6 月 24 日
Sounds like homework. Is it?
LOVLIPREET SINGH
2018 年 6 月 24 日
編集済み: LOVLIPREET SINGH
2018 年 6 月 24 日
回答 (2 件)
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
2018 年 6 月 24 日
編集済み: LOVLIPREET SINGH
2018 年 6 月 24 日
Walter Roberson
2018 年 6 月 24 日
Where did the tit come from, and what happened to tiy ?
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(:)]
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!