Info

此问题已关闭。 请重新打开它进行编辑或回答。

How can I improve this decoder

1 次查看(过去 30 天)
Sebastian Molina Sazo
关闭: MATLAB Answer Bot 2021-8-20
I have to do a decoder for this code, I made one, but the final string (string3) come out with the letters in the order that the encode code gives. What can i do to have the original order of the string? thanks for the help.
%% This is the encode code
function [string1,code]=codificar(string)
b=double(string);
if b(end)<b(1)
[a,c]=sort(b,'descend');
else
[a,c]=sort(b);
end
string1=char(a+1);
code=c;
end
%% And this is what a made
function [string3]=decodificar(string2) % I put string2 and 3 to no confuse with the original string
a=double(string2);
if a(1)<=a(end)
[b,g]=sort(a);
else
[b,g]=sort(a,'descend');
end
string3=char(b-1);
code=g
end
  2 个评论
Walter Roberson
Walter Roberson 2019-6-27
You cannot return to the original order without knowing the code variable. Consider that bard and brad would have the same output string1, so string1 by itself is not enough information to recover the original string.
Sebastian Molina Sazo
I have to put the original function in the decoder?

回答(0 个)

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by