Matrix Dimensions don't agree, importing data from excel

1 回表示 (過去 30 日間)
Antonio Martorano
Antonio Martorano 2019 年 8 月 6 日
回答済み: Star Strider 2019 年 8 月 7 日
I am working on a project that takes pressure coefficient data (upper and lower) based on X and Y locations on an airfoil from two separate excel files and uses them to numerically integrate and find the coefficient of lift, drag, and pitching moment about the leading edge of an airfoil. I am having difficulty with the dimensions of a and b not agreeing with Cpl and Cpu, which is preventing me from calculating fun2 as shown below. Is this an issue with the data I am pulling for Cpl and Cpu from excel not having limits, cause if I add arbitrary numbers to the columns to of the X and Y values in order to raise the a and b to the size of Cpu and Cpl, the Cpu and Cpl end up containing NA as values?
%% Initial Data
prompt = 'Enter an Angle of attack (degrees) ';
alpha = input(prompt);
prompt2 = 'Enter chord length ';
c = input(prompt2);
ac = c/4;
%% Extract Excel Data
BaseDir = 'C:\Temp';
[FileName, FilePath] = uigetfile('*.xlsx', ...
'Please select the UPPER pressure values Excel file', BaseDir);
File = fullfile(FilePath, FileName);
numData = xlsread(File);
x = numData(:,1);
yu = numData(:,2);
Cpu = numData(:,3); %Cpu
BaseDir = 'C:\Temp';
[FileName, FilePath] = uigetfile('*.xlsx', ...
'Please select the LOWER pressure values Excel file', BaseDir);
File2 = fullfile(FilePath, FileName);
numData2 = xlsread(File2);
Cpl = numData2(:,3); %Cpl
yl = -yu;
%% Calculation of Lift and Drag Coefficient
fun1 = (Cpl - Cpu);
a = (diff(yu)./diff(x));
b = (diff(yl)./diff(x));
fun2 = (Cpu.*a - Cpl.*b);
Cn = (1/c) * dot(fun1,diff(x));
%Cn = (1/c) * trapz(fun1.*diff(x))
Ca = (1/c) * dot(fun2,diff(x));
%Cn = (1/c) * trapz(fun2.*diff(x))
Cl = Cn*cosd(alpha) - Ca*sind(alpha);
fprintf('The Lift coefficient is,','\n')
disp(Cl)
Cd = Cn*sind(alpha) - Ca*cosd(alpha);
fprintf('The Drag coefficient is,','\n')
disp(Cd)
  3 件のコメント
Shubham Gupta
Shubham Gupta 2019 年 8 月 7 日
I think the issue is with using "diff" to calculate the derivative. So, if you have A as N x 1 vector then, diff(A) will give you (N-1) x 1 vector (it reduces 1 element from the vector).
Now, if you have x, yu, yl, Cpu, Cpl as same dimension, then
a = (diff(yu)./diff(x));
b = (diff(yl)./diff(x));
a and b calculated from above will result in 1 less element then the other vectors. Hence, there will be inconsistency in dimesion with other vectors
To fix this, you can use following approach, It adds 'zero' at first element to keep derivative's dimesion same as the original vactor.
try
a = [0;(diff(yu)./diff(x))]; % if a is Column vector
b = [0;(diff(yl)./diff(x))]; % if b is Column vector
catch ME
a = [0,(diff(yu)./diff(x))]; % if a is Row vector
b = [0,(diff(yl)./diff(x))]; % if b is Row vector
end
I hope it helps !
PS : I used "try" "catch" since I don't know the dimesion of a & b but depending on whether you know the dimesions beforehand you might not have to use this.
Antonio Martorano
Antonio Martorano 2019 年 8 月 7 日
@dpb when entering whos numData*
Name Size Bytes Class Attributes
numData 50x3 1200 double
numData2 50x3 1200 double

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2019 年 8 月 7 日
I am having difficulty with the dimensions of a and b not agreeing with Cpl and Cpu, which is preventing me from calculating fun2 as shown below.’
Use the gradient function instead:
a = (gradient(yu)./gradient(x));
b = (gradient(yl)./gradient(x));
The gradient function may not be the entire solution if your code has other problems, however it should solve the problem of the dimensions not being equal in your ‘fun2’ assignment.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by