Encode and Decode Problem
4 次查看(过去 30 天)
显示 更早的评论
clear, clc
a = [0 1 0 0 0 0 0 1];
b = [0 0 1 1 0 0 1 1];
c = xor(a,b);
%Write encoded message to a text file
fid = fopen('mycode.txt','w'); %Opens the file for write access
fwrite(fid,c);
fclose(fid);
disp(c);
%%
%Read and decode the encoded message from a text file
fid = fopen('mycode.txt','r'); %Open the file for read access
c = fread(fid);
fclose(fid);
a = xor(c,b);
disp(a);
I'm not sure why the code isn't displaying the decoded message, which should be [0 1 0 0 0 0 0 1]
0 个评论
采纳的回答
Walter Roberson
2020-4-6
编辑:Walter Roberson
2020-4-6
fread() returns a column vector by default.
c = fread(fid) .';
3 个评论
Ameer Hamza
2020-4-6
Neshant, as Walter has written. You need to use .' operator after the fread() call
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Mobile Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!