Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>New:</strong></p> <p>This is the best I could come up with. It should work for any number of comment lines and columns. You'll have to do the rest yourself if there are strings, etc. </p> <pre><code>% Define the characters representing the start of the commented line % and the delimiter COMMENT_START = '%%'; DELIMITER = ' '; % Open the file fid = fopen('testMixed.txt'); % Read each line till we reach the data l = COMMENT_START; while(l(1)==COMMENT_START) l = fgetl(fid); end % Compute the number of columns cols = sum(l==DELIMITER)+1; % Split the first line split_l = regexp(l,' ','split'); % Read all the data A = textscan(fid,'%s'); % Compute the number of rows rows = numel(A{:})/cols; % Close the file fclose(fid); % Assemble all the data into a matrix of cell strings DATA = [split_l ; reshape(A{:},[cols rows])']; %' adding this to make it pretty in SO % Recognize each column and process accordingly % by analyzing each element in the first row numeric_data = zeros(size(DATA)); for i=1:cols str = DATA(1,i); % If there is no '0x' present if isempty(findstr(str{1},'0x')) == true % This is a number numeric_data(:,i) = str2num(char(DATA(:,i))); else % This is a hexadecimal number col = char(DATA(:,i)); numeric_data(:,i) = hex2dec(col(:,3:end)); end end % Display the data format short g; disp(numeric_data) </code></pre> <p>This works for data like this:</p> <pre><code>% Comment 1 % Comment 2 1.2 0xc661 10 0xa661 2 0xd661 20 0xb661 3 0xe661 30 0xc661 </code></pre> <p>Output:</p> <pre><code> 1.2 50785 10 42593 2 54881 20 46689 3 58977 30 50785 </code></pre> <p><strong>OLD:</strong></p> <p>Yeah, I don't think LOAD is the way to go. You could try:</p> <pre><code>a = char(importdata('testHexa.txt')); a = hex2dec(a(:,3:end)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload