Encode and Decode Problem
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Neshant Thiru
el 6 de Abr. de 2020
Comentada: Walter Roberson
el 6 de Abr. de 2020
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 comentarios
Respuesta aceptada
Walter Roberson
el 6 de Abr. de 2020
Editada: Walter Roberson
el 6 de Abr. de 2020
fread() returns a column vector by default.
c = fread(fid) .';
3 comentarios
Ameer Hamza
el 6 de Abr. de 2020
Neshant, as Walter has written. You need to use .' operator after the fread() call
Walter Roberson
el 6 de Abr. de 2020
Alternately you can use
c = fread(fid, [1 inf]);
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Mobile Fundamentals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!