Question

Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of text file to write to Outputs: none File Outputs: 1. A text file containing all the permutations of the anagram Banned Functions: perms(), permute(), ipermute(), nchoosek (), combnk() Background: You guys know what do. You are professional MATLAB now, you got this! Function Description: Given a string, recursively determine all the unique ways to rearrange the letters. (i.e al the unique permutations). For example, if the string was abc, the list of permutations would be abc, acb, bac, bca, cab, cba. Write each permutation as a separate line in a text file, in alphabetical order. Case should be ignored and all letters should be lowercase in the output text file. Non-letter characters may occur in the string and should not be included. Characters may be repeated multiple times. There should be no newline character at the end of your file Notes: . Do not attempt to run this function with char vecs longer than about 10. If you do, you may be sitting around waiting a while The fourth test case will likely take a while, but all grading test cases will be shorter. » Hints: . The unique() function will be useful . You may need a wrapper function

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

Please find required MATLAB code along with necessary details in comments below:

--------------------------------------------------------- main_Script.m

clear all; clc;

str='pabc123'; % given string
filename='anagram.txt'; % file name where anagram have to be written
anagram(str,filename); % call the function

-------------------------------------------------------------------------- anagram.m

function anagram(str,filename)

% remove all the letters from the string
index = find(isletter(str));
fstr=str(index);
% convert all letters to lower case
fstr=lower(fstr);

% unique charcters in the string
unique_char=unique(fstr);
n=length(unique_char); % number of unique charcters in the string

% find all permulations of string
% all_comb=perms_letter(unique_char,n)
i=0;
for k=n:-1:1
i=i+1;
row_comb=[];
ntimes=n^(k-1);
for t=1:n^n/ntimes;
for j=1:n
% make all posssible combinations
row_comb=[row_comb;repmat(unique_char(j),ntimes,1)];
end
end
all_comb(:,i)=row_comb;
end

all_comb=cellstr(all_comb); % convert the chacter matrix into cell string

all_comb=unique(all_comb); % find unique strings from all combinations
all_comb=sort(all_comb); % sort strings in alphabetical order

fileId= fopen(filename,'w'); % open the file
fprintf(fileId,'%s\n',all_comb{:}); % write data to file
fclose(fileId); % close the file

========================================== SCREENSHOT OF CODE

main_script.managram m+ 1-clear all: clc; 3- str-pabc1 5- anagram (str, filename); % call the function 23% % given string filename=anagram . txt; % file name where anagram have to be written

=============================================== SAMPLE OUTPUT

Add a comment
Know the answer?
Add Answer to:
Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of...
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
  • Homework 02-Vectors, Strings, and Masking Function Name: forecast Inputs 1. (char) A character vector of the current fo...

    Homework 02-Vectors, Strings, and Masking Function Name: forecast Inputs 1. (char) A character vector of the current forecast 2. (char) The word to be replaced 3. (char) The new word to put into the forecast Outputs 1. (char) The updated forecast description Banned Functions strrep), replace), regexprep() Background You have recently started your internship as a weather engineer at the local news station. Unhappy with how the curment forecasts are described as 'gloomy" and 'cold, you decide to use MATLAB...

  • Goal:   Unscramble permuted words by generating all permutations of Jumble string and searching for a word...

    Goal:   Unscramble permuted words by generating all permutations of Jumble string and searching for a word in Unix dictionary. Unix Dictionary: dict.txt Details: Write a method called get_permutations that inputs a string like "dog". Your method should return an array of all permutations of the Jumble string. . For example: s = "dog" perms = get_permutations(a) print(perms) Output: ['dog', 'dgo', 'odg', 'ogd', 'gdo', 'god'] Rewrite the script for obtaining permutations and the end of the Comments, Hints, and Observersions section...

  • Add or Subtract. Write a function (add-sub-string s). The function consumes a Str of even length,...

    Add or Subtract. Write a function (add-sub-string s). The function consumes a Str of even length, where every even- numbered character is either "+" or "-", and odd-valued characters are numeric The function should add up all the digits that follow a "+", and subtract all the digits that follow a "-". For example, (add-sub-string "+3+4-5") => 2 (add-sub-string "-5+3+4-6-6") - 10 => The interface file contains the function char->nat that converts a numeric Char to the corresponding numeric value....

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • for matlab Function Name: ​vineCompilation Inputs: (​char​) The first vine quote (​char​) The second vine quote...

    for matlab Function Name: ​vineCompilation Inputs: (​char​) The first vine quote (​char​) The second vine quote Outputs: 1. (​char​) A “compilation” of the vines Background: It’s Sunday afternoon and you’re hanging out in your lounge, finishing off your Sprite Cranberry. Your Mom FriendTM (Jared, 19) walks in and yells at you for drinking soda for breakfast. Aggravated, you YEET the empty can down the hall as Jared drags you to the kitchen to make breakfast. You open the fridge to...

  • Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array...

    Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array listing words and their counts in sorted order Function Description: Have you ever seen those fancy word-clouds based on the frequency of word occurrences in some text? Well the first step of making a graphic like that is to figure out how often the words in some text occur, which is exactly what this function will do. You will count the number of occurrences...

  • 2. This question is about processing strings 2.1 [4 marks] Given a string str, we can...

    2. This question is about processing strings 2.1 [4 marks] Given a string str, we can calculate a checksum of the string by summing up the ASCII codes of the characters in the string. For example, the checksum of a string "apple" is 530, which equals to 'a' + 'p' + 'p' + 'l' + 'e' = 97 + 112 + 112 + 108 + 101. Write a function int calculate_checksum(char str[] that calculates and returns the checksum of the...

  • you need to write a C function named rem. The prototype is: int rem(char*, char*); The...

    you need to write a C function named rem. The prototype is: int rem(char*, char*); The function accepts 2 strings: the first is a string of text to process; the second is where the output will be placed. rem() should remove all occurrences of a lowercase 'x' from the first string, and save the resulting string in the second arg. You may use the strlen() function; no other built-in fuctions should be used. Test your program thoroughly. Then, once you...

  • Write a function in matlab for these parameters (char) A string representing 7 days of the...

    Write a function in matlab for these parameters (char) A string representing 7 days of the week (eg. 'N M T W R F S') (double) A vector representing 7 dates of the week (eg. [4 5 6 8 79 10]) (double) A positive or negative number of days (char) A string representing 7 days of the new week (double) A vector representing 7 dates of the new week circshift() It's fairly simple to determine what the date was or...

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