different operations for same string

lets say i have a string (string=('aBcdEf')). how do i make something like that?
output1= function on A to C (upper and lower case)
and
output2=function on D to F(upper and lower case)
Thank you

5 件のコメント

dpb
dpb 2018 年 10 月 14 日
What does "function on (letter set)" mean, precisely?
It's simple enough to find the set members, the Q? is what is supposed to happen?
Give an example of expected outputs desired.
Elie Elias
Elie Elias 2018 年 10 月 14 日
編集済み: dpb 2018 年 10 月 14 日
For the characters in the first half of the alphabet ('A' to 'M' and 'a' to 'm'), convert them to the characters:
  • A position further in the ASCII table if the difference between the ASCII code of the current character and the next prime number is odd.
  • Two positions further in the ASCII table if the difference between the ASCII code of the current character and the next prime number is even.
Sorry if the question isnt clear, i google translated it from french
Elie Elias
Elie Elias 2018 年 10 月 14 日
編集済み: dpb 2018 年 10 月 14 日
basically this i what i have to do but i dont know how to do an operation on the characters A to M in one string
madhan ravi
madhan ravi 2018 年 10 月 14 日
編集済み: madhan ravi 2018 年 10 月 14 日
Just give an example of your required output
Image Analyst
Image Analyst 2018 年 10 月 14 日
Clear as mud. When you say "the next prime number"? What is the current prime number? And as you know, the only even prime number is 2, so the next prime number being even would only be if the CURRENT prime number is 1, but we don't even know how you're obtaining any of these these prime numbers.
Try to read this link

サインインしてコメントする。

 採用された回答

dpb
dpb 2018 年 10 月 14 日
編集済み: dpb 2018 年 10 月 15 日

0 投票

Sounds pretty French to me! :)
function s=strfutz(s)
% futz with characters in string
% generate the test prime set
%P=primes(200);P=P(find(P<'A',1,'last'):find(P>'z',1));
P=[61 67 71 73 79 83 89 97 101 103 107 109 113 127];
isOdd=@(x) logical(mod(x,2)); % convenient shorthand
isEven=@(x) ~isOdd(x);
u=upper(s);
ix=ismember(u,'A':'M'); % first group
ix=find(ix); % absolute address in string
io=isOdd(interp1(P,P,double(s(ix)),'next')-s(ix));
ifix=ix(io); % pick the odd ones out
s(ifix)=s(ifix)+1; % and increment the ASCII code
ie=~io; % even aren't odd
ifix=ix(ie); % pick the even ones now
s(ifix)=s(ifix)+2; % and increment the ASCII code
end
Some of the intermediaries could be fold together, but I believe this does what your description asks for.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

質問済み:

2018 年 10 月 14 日

編集済み:

dpb
2018 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by