Question

In Matlab and not using any built in functions write a function that will take in...

In Matlab and not using any built in functions write a function that will take in a word and a specific letter. It will then return a list of all the positions in the word where that letter exists.  function indexes = find_letter_positions( word, letter )

Example of output.

>> find_letter_positions('hello', 'h')
ans =
[ 1 ];
>> find_letter_positions('hello', 'l')
ans =
[ 3 4 ];
>> find_letter_positions('hello', 'z')
ans = [ ]; % an empty array

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function indices= find_letter_positions(word, letter)
word='hello'
n=length(word)
letter='h'
a=zeros(1,n)
for i=1:n
  
if(word(i)==letter)
a(i)=1
end
end
j=1
for i=1:n
if(a(i)==1)
indices(j)=i
j=j+1
end
end

New Variable Analyze Code Find Files D Open Variableun and Time Set PathHe Request Support New New Open Compare import Save 3

Add a comment
Know the answer?
Add Answer to:
In Matlab and not using any built in functions write a function that will take in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • No loops can be used and must only use functions that are built into matlab, aka...

    No loops can be used and must only use functions that are built into matlab, aka no toolboxes FACTORS All Factors of an Integer FACTORS(N) returns all the factors of the positive integer N. For example: FACTORS(60) returns the 2 X 6 array [ 1 2 3 4 5 6 60 30 20 15 12 10] FACTORS(25) returns the 2 X 2 array [ 1 5 25 5] FACTORS(7) returns the 2 X 1 array [1 7] If N is...

  • write a Matlab program ( solve the three questions). please use array and create your own...

    write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...

  • using basic c++ and use no functions from c string library b) Write a fragment of...

    using basic c++ and use no functions from c string library b) Write a fragment of code (with declarations) that reads a pair of words from the keyboard and determines how many letters in corresponding positions of each word are the same. The words consist only of the letters of the English alphabet (uppercase and lowercase). For example, if the words are coat and CATTLE, the following output should be generated: 012245 0122 matching letter in position 0 t is...

  • C++ Linux Compiler Letter Frequency Write a function that will take a string and return a...

    C++ Linux Compiler Letter Frequency Write a function that will take a string and return a count of each letter in the string. For example, "my dog ate my homework" contains 3 m's, 3 o's, 2 e's, 2 y's and one each of d, g, a, t, h, w, r and k. Your function should take a single string argument and return a dynamically allocated array of 26 integers representing the count of each of the letters a .. z...

  • Write a templated function sumList that will take in an array of any type and the...

    Write a templated function sumList that will take in an array of any type and the length of the array. It should add all the elements in the array and return the total. Hint: you can declare a variable sum of type T and initialize it like this: T sum {}; The {} are the best way to make sure that numbers get set to 0, a string gets created as empty etc... #include <iostream> using namespace std; //Do not...

  • Write a function in HASKELL to reverse a string (or list) without using the built-in reverse...

    Write a function in HASKELL to reverse a string (or list) without using the built-in reverse function.           Example:           Hello as olleh or [1,3,4,5] as [5,4,3,1].

  • Use the language c++ and answer the followig questions: 1) Write a function that will take...

    Use the language c++ and answer the followig questions: 1) Write a function that will take an empty array of size 25 as input and modify each element such that the array stores values from 1 to 25. 2) Write a function to print this array to show your output. 3) Write a function to iterate through that array and print whether or not a number is: even, odd, and prime. ... Make sure to call your functions in main()...

  • Use the FDR to design and write a function, maxValTimes, that takes a list of integers...

    Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set.   For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...

  • In matlab, there is a function "size" that accepts an array as a parameter (or input...

    In matlab, there is a function "size" that accepts an array as a parameter (or input argument) and returns the dimensions of that array as another single-dimension array.      For example, if the array were 2 x 2, it would return [2 2]. Assume that input1 is a 1 or 2-dimensional array. Use the size function to obtain the dimensions and save the output into the return argument of this function "output1"     1Do not modify the line below 2-unction...

  • in MATLAB code/syntax please 3) (Chap 7 problem) Write a function newwords that will receive a...

    in MATLAB code/syntax please 3) (Chap 7 problem) Write a function newwords that will receive a word in a character vector as an input argument. It will then randomly scramble the letters and return the result. Here is an example of calling the function: >> newwords ('exceptional) ans 'tponexlicae

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT