Find a letter position within a word.

조회 수: 2 (최근 30일)
JEE
JEE 2018년 4월 18일
댓글: Walter Roberson 2018년 4월 20일
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
JEE
JEE 2018년 4월 18일
Correct
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