Question

***write in matlab. ****use while loops shuffletext Write a function shuffletext( pairs, s) that swaps characters of s as specified by the indices present in the pai

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

% idea is to check each pair in the list of pair and swap the character for

% those two indexes

function s = suffletext(pair, s)

i = 1;

while i <= size(pair, 1)

%exract the two index from pair

temp = pair(i, :);

% swap the two characters

t = s(temp(1));

s(temp(1)) = s(temp(2));

s(temp(2)) = t;

i = i + 1;

end

end

Add a comment
Know the answer?
Add Answer to:
***write in matlab. ****use while loops shuffletext Write a function shuffletext( pairs, s) that swaps characters of s...
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
  • 1. (100 pts) Write a program that swaps the elements of an array pairwise. Start from...

    1. (100 pts) Write a program that swaps the elements of an array pairwise. Start from the left of the array, take 2 elements at a time and swap the two elements. Continue in this fashion until you reach the end of the array. Declare an integer array of size 10 and place random numbers in the range [0?9]. Print the original array, pairwise swap the elements of the array and print the final array after swap. Consider the following...

  • Write a program that, given a starting location in a 2D grid of characters, will count...

    Write a program that, given a starting location in a 2D grid of characters, will count how many contiguously connected @ symbols there are. Cells have to be direct neighbors either horizontally or vertically to count as contiguous. However, the right/left and top/bottom edges ARE considered to be connected – you can “wrap around” from one side of the matrix to the opposite one. The grid of chars will always be 10x10. Your program should load the grid of chars...

  • MATLAB Write the proper 'display header' for each part. Give a short comment in front of...

    MATLAB Write the proper 'display header' for each part. Give a short comment in front of each line as needed. (1a)-Create a variable calls final_value which is holding a value of 30. (1b)-Create a row vector from 20 to the final_value with an increment of 8.(Do not use the value of final_value). Next, assign this vector to a variable calls row_vec1. (1c)-Use the length() function to create another row vector using linspace() from 2 to 56 and assign it to...

  • Matlab Question: Important! Read: No for or while loops may be used; must use the disp...

    Matlab Question: Important! Read: No for or while loops may be used; must use the disp function The top speeds of sportscars, given in miles per hour, are: 155 mph BMW M5 217 mph Lamborghini Aventador Spyder 205 mph Ferrari 488 205 mph Nissan GTR 197 mph Chevrolet Corvette Stingray ZR1 258 mph Bugatti Veyron Supersport 195 mph Dodge Viper 270 mph Hennessey Venom 155 mph BMW M3 195 mph Mercedes SL Write a function selectCars to identify cars with...

  • Write a Java program that calculates the sum of a variable sized matrix using a two...

    Write a Java program that calculates the sum of a variable sized matrix using a two dimensional array. (ArraySum.java) The user should provide the number of rows and columns Test multiple user inputs (3 times 2, 4 times 4, 6 times 2, etc) A sum should be created for each row, each column, and the total for the matrix Ex.: How big would you like your matrix? Rows - ? 3 Columns -? 2 Please enter your row 1? Column...

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

  • Matlab problem Write a function matsort to sort all of the values in a matrix (decide...

    Matlab problem Write a function matsort to sort all of the values in a matrix (decide whether the sorted values are stored by row or by column). It will receive one matrix argument and return a sorted matrix. Do this without loops, using the built-in functions sort and reshape. For example: >> mat mat- 4 5 2 1 3 6 7 8 4 9 1 5 >> matsort(mat) 1 4 6 1 4 7 2 5 8 3 5 9...

  • Given a matrix of size NxM sorted in descending order and value V, write a function...

    Given a matrix of size NxM sorted in descending order and value V, write a function which returns -1 if value V is not in the matrix, else it returns 1 if V is in the matrix. The function also computes the position of V in the matrix, that is P= [R, C], where R is the row number of V and C is the column number of V in the matrix, if V is in the matrix (if V...

  • on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A,...

    on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A, of matrix A is accesser (3) Correcting an entry is easy to (4) Any submatrix of Ais obtained by d row wise. Rows are separated by semicolons and columns are separated by spaces ner A l 23:45 6. B and hit the return/enter kry matrix A is accessed as A Enter and hit the returnerter key an entry is easy through indesine Enter 19...

  • matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

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