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]

 채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 6일
편집: Walter Roberson 2020년 4월 6일

0 개 추천

fread() returns a column vector by default.
c = fread(fid) .';

댓글 수: 3

Neshant Thiru
Neshant Thiru 2020년 4월 6일
How would I make it a row vector?
Ameer Hamza
Ameer Hamza 2020년 4월 6일
Neshant, as Walter has written. You need to use .' operator after the fread() call
Alternately you can use
c = fread(fid, [1 inf]);

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by