본문 바로가기
유용한 지식/Matlab

Get Matlab Excel Data | xlsread function

by 그래도_明 2020. 9. 24.

Get Matlab Excel Data | xlsread function

When you conduct an experiment and process data with a matlab, sometimes you want to recall the data values in an Excel file right away. Let's briefly learn how to use the xlsread function by using the following example.

 

First of all, the data obtained through the simulation program is recorded in the excel file as shown above. As you can see, the file lists the values of the data over time.

 

To take the data in this Excel as a variable in the Matlab and store it in matrix form, you can use the xlsread function in the command window or script window of the Matlab.

 

data=xlsread('Simulation Data.xlsx',1);

The code above refers to a variable named data that brings up the values of sheet1 in the Excel file called 'Simulation Data.xlsx'.

At this time, the following words may appear and may not be uploaded. I used the Korean version. Translating it means 'the file can't be open' and 'the file can't be found at the location'.

This can be resolved by designating the current folder in the matlab as the location of the file because the file's routing is incorrect.

he following is a correct representation of the data stored in a variable. Depending on the size of the file, it may take a long time.

Since the first column in this data meant time, only the first column is extracted and stored separately in a variable called t.

t=data(:,1)';

Similarly, other data can be extracted separately by specifying the appropriate variable names.

Estimation=data(:,2)';
Real=data(:,3)';

Finally, you can create a graph with these organized variables.

plot(t,Estimation,'r',t,Real,'k:')
legend('Estimation Angle','Real Angle')
grid on
axis([0.4 0.54 0 6.5])

반응형

댓글