Find a letter position within a word.

2 次查看(过去 30 天)
I need to right a function that will take in a word and a letter. Then return a list of all the positions in word where the letter exists. I need to figure out how to do this without using any built in functions. So far I have :
function result = find_letter_positions(word,letter)
indexes = [];
for i = 1:length(word)
if word(i) = = letter
after this I am unsure of where to go
  3 个评论
Walter Roberson
Walter Roberson 2018-4-20
Please do not close Questions that have an Answer

请先登录,再进行评论。

采纳的回答

Birdman
Birdman 2018-4-18

This might help you:

function indexes = find_letter_positions(word,letter)
indexes = zeros(1,numel(word));
for i = 1:numel(word)
    if word(i)==letter
        indexes(i)=i;
    end
end
indexes=indexes(indexes~=0);
end
  1 个评论
Stephen23
Stephen23 2018-4-18
Note that zeros, numel, and indexing (using subsref) are all inbuilt functions.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by