Write a function catit1 that will receive one input argument, which is a cell array. If the cell array contains only strings, it will return two strings : one string is all of the strings from the cell array concatenated together, the other string is

Question: Write a function catit1 that will receive one input argument, which is a cell array. If the cell array contains only strings, it will return two strings : one string is all of the strings from the cell array concatenated together, the other string is combing the last alphabets of each word in cell array. Otherwise, it will return two empty strings.
>>fishies={tuna, shark, salmon}
>>[str1,str2]=catit1(fishies)
str1= tunasharksalmon
str2= akn
I am having trouble figuring out how to get the strings to both concatenate and encrypt. Without the str2 input at the bottom, the str1 concatenation works fine.
fishies = {'tuna','shark','salmon'};
[str1,str2] = catit1(fishies);
function [str1,str2] = catit1(ca)
str1 = '';
if iscellstr(ca)
for i = 1:length(ca)
str1 = strcat(str1,ca{i});
end
end
car = char(ca);
rest = strtrim(car);
str2 = '';
while ~isempty(rest)
[word,rest] = strtok(rest);
str2 = strcat(str2,word(end));
end
end

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by