Create a matrix of HEX number from a file of HEX number separated by a space
3 views (last 30 days)
Show older comments
benjamin ktorza
on 17 Aug 2023
Commented: benjamin ktorza
on 18 Aug 2023
Hi,
I have a file containing a lot of lines. each line contains a set number of HEX values separated by spaces (in the file 24 HEX number and 12 lines)
I would like to make is a variable that is a matrix (24x12 in the test file). the number can either stay as a string, be converted as hex or be dec equivalent, it doesn't matter too much.
thank you in advance
0 Comments
Accepted Answer
Walter Roberson
on 17 Aug 2023
Edited: Walter Roberson
on 17 Aug 2023
S = readlines('test.txt');
S(strlength(S) == 0) = []; %end of file usually comes through as empty line
SS = regexp(S, '\s+', 'split');
wanted = vertcat(SS{:})
Note: the code, as written, will fail if there are lines with fewer (or more) values.
More Answers (1)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!