How can I change the letters in a string input but not the other characters?

조회 수: 5 (최근 30일)
Natalie Oyenarte
Natalie Oyenarte 2020년 10월 24일
댓글: Walter Roberson 2020년 10월 27일
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 10월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Alan Moses
Alan Moses 2020년 10월 27일
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!

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by