Search code examples
matlabhexfwrite

Row wise writing to file using fwrite() in Matlab


enter image description herefwrite in Matlab writes in column order. This is a problem for me as I need to write hex values which should be read byte wise and then go to the next row and so on. Is there a way this can be done? Below is my code.

hexvec = dec2hex(bytevec,2);
fileID = fopen('my_flipped_data_new.bin','wt');
fwrite(fileID, hexvec);
fclose(fileID);

Thanks!


Solution

  • think I got your point.

    CODE:

    F=dec2hex(1:63,2);
    F=[char(F),repmat(' ',length(F),1)]'
    F=F(:)'
    fileID = fopen('my_flipped_data_new.bin','wt');
    fwrite(fileID, F);
    fclose(fileID);
    

    OUTPUT (text file):

    01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F