Download presentation
Presentation is loading. Please wait.
1
Importing Excel Data & Exporting Data to Excel
2
Importing Data from Excel
Data is easily imported from Excel to MATLAB by using the xlsread function. >> ArrayName = xlsread(‘filename’,CellsToBeRead) The Import tool can also be used to import data from Excel.
3
Creating a Vector from Excel Data
Be sure to save LEC3_excel_example.xlsx into your MATLAB working directory Open the file in excel. You will notice that the file has headings in column A and B while the date goes from cell A2:B22. In Matlab type, >> data = xlsread(‘LEC3_excel_example.xlsx’, ‘A2:B22’) 4. Notice the output ( do not use a ; to suppress the output) 5. You can do many operations with the 2 column vector called data.
4
Creating a plot from Excel Data
In Matlab type, >> data = xlsread(‘LEC3_excel_example.xlsx’) 2. Notice the output ( do not use a ; to suppress the output) 3. You can do many operations with the 2 column vector called data. It has also ignored the headings!! 4. Please suppress the output in your script files unless you want to see the output. 5. Now to plot the data. Look at the headings in the excel file. They are time and power. Time looks manipulated so it goes on the x axis. 6. Type in Matlab >> time = data(:,1) 7. Notice a 1 column vector named “time” 8. Now type in Matlab >> power = data(:,2) Notice a 1 column vector named “time” 9. Now plot time on x axis and power on y axis. Type in Matlab >> plot(time,power)
5
Creating a plot from Excel Data
1.Type in Matlab >> poly2nd = polyfit(time,power,2) 2.Notice the output >> poly2nd = If you need more decimal places use the ‘format long’ command 3. The best fit equation to a second order polynomial would be y=2.9817x^ x 4. Place the data and the fitted line on the plot >> t=time; >> p=2.9817*t.^ *t ; >> plot(time,power,t,p) >> legend('data','fit')
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.