How can I change the letters in a string input but not the other characters?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/391058/image.png)
1 Kommentar
Walter Roberson
am 24 Okt. 2020
Your code has no documentation as to what it is intended to calculate, so as outside volunteers looking at it with no knowledge of purpose, we must assume that the code is correct and that you are mistaken about the code being wrong.
Antworten (1)
Alan Moses
am 27 Okt. 2020
It is my understanding that only the letters in the string input must be changed according to the logic of the script and other characters be retained. You may use the below script to achieve this:
function coded = hw5_problem1(txt)
coded = txt;
small = isstrprop(txt,'lower');
big = isstrprop(txt,'upper');
coded(small) = char(219-txt(small));
coded(big) = char(155-txt(big));
end
Hope this helps!
1 Kommentar
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!