Search code examples
excelmatlabmatlab-guidexlsread

Read excel file and assign each coulmn a variable in MATLAB


I am having a simple problem while reading excel data which contains strings, long string, and numbers. Now I need to make each column (I have 11 here) to define separate variables of 1 column vector so that I can plot in MATLAB against each other or combination.

But the problem is the reading the file and creating 11 column vector. When I assign variable the header also comes.

Code:

%fid = fopen('Data_Link.xlsx');
[num,txt,raw] = xlsread('Data_Link.xlsx');
%fclose(fid);

% Extract data from readData
A = raw(:,1);
B = raw(:,2);
C = raw(:,6);

So I need the variables without header

Data file is truncated and given here.

Can anyone help me?


Solution

  • You can use readtable as ThP suggested. But if you want to use xlsread and you want your data without the header, you just need to remove the first row as in the below example:

    %fid = fopen('Data_Link.xlsx');
    [num,txt,raw] = xlsread('Data_Link.xlsx');
    %fclose(fid);
    
    % Extract data from readData
    A = raw(2:end,1);
    B = raw(2:end,2);
    C = raw(2:end,6);
    

    Note that each array will receive data from row 2 to last row.