nCol=4;
fid=fopen('data.txt','r');
M=fscanf(fid,'%2x',[nCol,inf]).';
fid=fclose(fid);
I can't for the life of me understand why TMW left the hex conversion out of textscan/textread but they did... :(
NB: Above presumes the file was written as '%02X'; ie, each value does indeed have two digits, not any leading blanks (altho not tested, I think it'll still work if there were a delimiter in that case, but not if there is no delimiter.
5 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379708
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379708
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379711
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379711
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379794
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379794
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379801
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379801
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379925
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/296019-reading-txt-file-and-converting-hex-to-decimal-and-plotting#comment_379925
Sign in to comment.