Matlab - importing data from excel & interpolating

In summary, the conversation discusses the need to retrieve data from an excel sheet for a wind turbine project. The current method of using Excel's line of best fit approximation has a high margin of error, so the person is looking to import the data to excel and use Matlab's interpolate function for more accurate values. They are unsure of how to import the data and use the function, but it can be done through the GUI and Matlab's documentation provides guidance on interpolation.
  • #1
DyslexicHobo
251
0
I have data that I'm using for a wind turbine project. The project requires that I retrieve data from an excel sheet that was supplied of experimentally tested values for lift and drag. These values for lift and drag are based on a value alpha (an angle, but irrelevant to the coding question).

Right now, I have used Excel's line of best fit approximation (using a 6th degree polynomial) along with different if statements to get the values, but I've found that there can be up to 30% error in some calculations. Instead, I'd like to import the data to excel and use Matlab's interpolate function to find these values.

The only problem is... I have no clue how to go about importing the data to excel or how to use the interpolate function. My Matlab experience is literally non-existent. I have minor experience in Java but that's it.

What's the easiest way to import the data from excel, and what functions can I use to interpolate the data? Thanks!

Here's the code I'm trying to replace:
Code:
            %FINDING CL
            if(alpha>0 && alpha <= 8)
                Cl = -0.0001*alpha^5 + 0.0016*alpha^4 - 0.0093*alpha^3 + 0.0219*alpha^2 + 0.0928*alpha + 0.0006;
            elseif(alpha > 8 && alpha <= 27)
                Cl = -.00001*alpha^2 + 0.0542*alpha - 0.5037;
            elseif(alpha > 27 && alpha <= 90)
                Cl = -.00000009*alpha^4 + .00003*alpha^3 - 0.0036*alpha^2 + 0.1761*alpha - 1.8521;
            else
                Cl=0;
            end

            %FINDING CD
            if(alpha >= 0 && alpha <= 8)
                Cd = -.00001*alpha^3 + 0.0003*alpha^2 - 0.0003*alpha + 0.0134;
            elseif(alpha > 8 && alpha <= 90)
                Cd = -.0000000004*alpha^5 + .0000002*alpha^4 - .00003*alpha^3 + 0.0018*alpha^2 - 0.0196*alpha + 0.1616;
            else
                Cd = 0;
            end
 
Physics news on Phys.org
  • #2
DyslexicHobo said:
What's the easiest way to import the data from excel,

Locate your data file in Matlab's 'Current Directory' window. Right-click on the file and select 'Import Data'. The use the GUI to import the data into matlab.

DyslexicHobo said:
and what functions can I use to interpolate the data? Thanks!

Matlab's documentation discusses interpolation and fitting at great length. Use the help browser to search for 'Interpolation'.
 
  • #3


First of all, it's great that you are looking into using Matlab for your project. It is a powerful tool for data analysis and can definitely help improve the accuracy of your calculations.

To import data from Excel into Matlab, you can use the "xlsread" function. This function allows you to specify the file name and sheet name from which you want to import data. You can also specify the range of cells that you want to import.

For example, if your data is in a sheet called "Experiment Data" in an Excel file called "Wind Tunnel Data.xlsx", and the data you want to import is in the range A2:B100, your code would look something like this:

[num,txt,raw] = xlsread('Wind Tunnel Data.xlsx','Experiment Data','A2:B100');

This will import the data into three variables - "num" for numeric data, "txt" for text data, and "raw" for the raw data as it appears in Excel.

Once you have imported the data, you can use the "interp1" function to interpolate the values for lift and drag based on the angle alpha. This function takes in the x and y values for your data and the desired x values for interpolation. For example, if your alpha values are in the first column of "num" and your lift values are in the second column, your code would look something like this:

Cl = interp1(num(:,1),num(:,2),alpha);

This will give you the interpolated value for lift at the specified alpha angle. You can do the same for drag using the appropriate column from your imported data.

I would also recommend looking into the "fit" and "fittype" functions in Matlab, which can help you create a more accurate fit for your data instead of using a high degree polynomial. You can also plot your data and the fit to visually inspect the accuracy.

Overall, importing data and using interpolation in Matlab is fairly straightforward once you get the hang of it. I suggest looking into some tutorials or online resources to familiarize yourself with the basics of Matlab. Good luck with your project!
 

1. How can I import my data from excel into Matlab?

To import data from excel into Matlab, you can use the "xlsread" function. This function allows you to specify the file name, sheet name, and range of cells that you want to import. You can also import data from multiple sheets or files at once.

2. What is the best way to handle missing data when importing from excel to Matlab?

One way to handle missing data is to use the "NaN" value, which stands for "Not a Number". This value can be used in place of missing data in your excel file, and Matlab will recognize it as a missing value when importing. Alternatively, you can also use the "readtable" function to import your excel data as a table, which allows you to specify how you want missing data to be handled.

3. Can I import data from specific cells or columns in excel?

Yes, you can import data from specific cells or columns by specifying the range of cells or columns in the "xlsread" function. You can also use the "readtable" function to import data from specific columns in excel.

4. How do I interpolate my data in Matlab?

To interpolate your data in Matlab, you can use the "interp1" function. This function allows you to specify your x and y data points, as well as the type of interpolation method you want to use (linear, cubic, etc.). It will then create a new set of data points based on the interpolation method you chose.

5. Is there a way to plot my interpolated data in Matlab?

Yes, you can plot your interpolated data in Matlab using the "plot" function. Simply input your original x and y data points, as well as the interpolated data points, and Matlab will create a plot for you. You can also customize the plot by adding labels, titles, and adjusting the axis limits.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
7K
Replies
12
Views
8K
Back
Top