MATLAB: How to read a term of the file

.dat

Hi, I would know if someone can help me with this. In the file I have, I only need to read the third term of the second column, I mean, the total_z colum, which in the first row is -9.471316e-01. So I need to obtain this term of all the file.
Thanks

Best Answer

  • Hello,
    Here is a solution that you can refer:
    clear
    format long
    a = readtable('force1.dat','HeaderLines',4);
    b = a(:,4);
    c = b{:,1};
    n = length(c);
    d = zeros(n,1);
    for i = 1:n
    d(i) = str2double(c{i}(1:end-1));
    end
    d(1)
    Your data is now saved in varibale d.
    Best rergards,
    Trung