Question
Matlab. Please add comments. Thank you in advance.
15. Write a code that can read in a string and replaces all vowels with xs 16. Write a function that reads in a D array of any length, u, and swaps elements of the array in the following way. The first and last element are swapped. The second and second to last element are swapped. The third and third to last element are swapped, and so on until all the elements get swapped. Output the swapped array.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB Code:

(15)

function retval = changeVowels (input1)
% Function that replaces all vowels with x's
  
retval = lower(input1);
  
% Iterating over input string
for i=1:length(input1)
% Checking for vowels
if (retval(i) == 'a' || retval(i) == 'e' || retval(i) == 'i' || retval(i) == 'o' || retval(i) == 'u')
retval(i) = 'x';
end % If ebd
end % For end
  
end % function end

Sample Run:

Command Window >changeVowels (hello world) 7 7 7

___________________________________________________________________________________________________

(16)

function retval = swapArray (input1)
% Function that swaps the array elements
  
% Copying array
retval = input1;
  
% Last index
j = length(input1);
  
% Iterating over half of the array
for i=1:length(retval)/2
  
% Swapping elements
temp = retval(i);
retval(i) = retval(j);
retval(j) = temp;
  
j = j-1;
  
end % For end
  
end % function end

Sample Run:

Command Window swapArray ([10 20 30 40 50 60 70 80]) ans - 80 70 60 50 40 30 20 10

Add a comment
Know the answer?
Add Answer to:
Matlab. Please add comments. Thank you in advance. 15. Write a code that can read 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
  • using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last in...

    using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...

  • JAVA / please add comments Write code for a method named loadDatagrams() that returns an array...

    JAVA / please add comments Write code for a method named loadDatagrams() that returns an array of type Datagram. The method will read from the filepath C:/folder/grams.dgf and the file contains an array of type Datagram ( you may assume that the class definition is visible to the method) Remember to include appropriate exception handling

  • Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume...

    Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1....

  • Write code in static void main method class, which creates a boolean array called flags, size...

    Write code in static void main method class, which creates a boolean array called flags, size 10, and using a for loop sets each element to alternating values (true at index zero, false at index one Write code in a static void main method class, which creates a float array called sales, size 5, uses an initializer list to instantiate its elements with positive values having two decimal places (example 7.25), and using a for loop reads those values of...

  • Write the code in PYTHON and please provide the full code, thank you! Write a program...

    Write the code in PYTHON and please provide the full code, thank you! Write a program that plots two functions: f(x) = x2 and g(x) = ax. Write it in such a way that the intersection points are marked with an X, for arbitrary a. • You may use your favorite ready-made function to find the intersection points, if not: • One possible way to tackle this problem is to put both function values in arrays and check using a...

  • Please write a MATLAB code for this 4. Create a function called changearray(A) that would add...

    Please write a MATLAB code for this 4. Create a function called changearray(A) that would add 20 to all non-positive elements of an array A and take the natural logarithm of all positive elements of A? >> A = randn (4,5) *5 A = 1.5176 -3.0016 2.4498 3.6968 8.5594 -0.9706 -10.6918 -4.1979 6.7730 -5.3608 4.8048 0.6202 7.1835 -9.8045 -0.9885 -6.0392 14.5400 4.1261 6.8949 -5.2909 >> changearray (A) 0.4171 2.1470 16.9984 19.0294 0.8960 9.3082 1.307515.8021 1.91291.9718 14.6392 10.1955 1.5696 19.0115 -0.4776...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • PLEASE ADD COMMENTS EXPLAINING EACH LINE OF CODE THANK YOU QUES TION 7 10 points Save...

    PLEASE ADD COMMENTS EXPLAINING EACH LINE OF CODE THANK YOU QUES TION 7 10 points Save Answer The following program tries to print all the elements of the numbers list. However, it does not work! Please describe the issue and fix the error. numbers-3,5,7,9 for i in (len (numbers)): print (numbers [i]) TTT Arial ▼T. :- . -. , 3112pt) Path:

  • Can someone please help me with this code? I'm writing in C++. Thank you in advance....

    Can someone please help me with this code? I'm writing in C++. Thank you in advance. Complete a program that represents a Magic Eight Ball (a Magic Eight Ball allows you to ask questions and receive one of several random answers). In order to complete this, you will need a couple of new functions. First, in order to get a line of input that can contain spaces, you cannot use cin, but instead will use getline: string question; cout <<...

  • Please add comments line for matlab and show all step in paper, ASAP. Thanks in advance....

    Please add comments line for matlab and show all step in paper, ASAP. Thanks in advance. 0.24 Hyperbolic sinusoids-In filter design you will be asked to use hyper bolic functions. In this problem we relate these functions to sinusoids and obtain a definition of these functions so that we can actually plot them (a) Consider computing the cosine of an imaginary number, i.e., use cos(x) 2 let j and find cos(x). The resulting function is called the hyper- bolic cosine...

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