Interp1 error VqLite = F(Xqcol)
조회 수: 5 (최근 30일)
이전 댓글 표시
clc;clear;
Filename= 'Homework 2 Dropsonde Updated2.xlsx';
T=readtable(Filename);
T.AirTemp= T.AirTemp + 273.15;
%Humidity Graph After Converson
R=T.RelHumid;
Temp= T.AirTemp;
p=T.AirPress;
A=[];
for i=1:length(R)
Aval=6.12*(R(i)/100)*(exp((17.67*(Temp(i)-273.15))/(Temp(i)-29.65)))*(p(i)/1013.25);
A(end+1) = Aval;
end
A= A';
%figure(3)
%plot(A,T.GeopotenAltitude)
%Question 1a
N=[];
for i=1:length(Temp)
Nval= (77.6/Temp(i))*(p(i)+ ((4810*A(i))/Temp(i)));
N(end+1)= Nval;
end
N= N';
% figure(1)
% plot(N,T.GeopotenAltitude)
% title('ECE 6735 HW2 Problem 1a');
% xlabel('Refractivity (mbar)');
% ylabel('Altitude (m)');
%Question 1c
alt= T.GeopotenAltitude;
n0=interp1(alt,N,0);
angle= deg2rad(0.2);
deltaX= 0.2;
h=0;
x=0;
Re= 6371 *10^3;
while h< 1000
alt
N
h
nh=interp1(alt,N,h);
h= h+ deltaX* sqrt((angle^2)+(2*(nh+(h/Re)-n0)));
x=x+deltaX;
end
So I am trying to create a code that takes in data from an exel and then uses the interp1 function to find the N value at that given height. I set h=0 sicne I am starting on the ground but when I use nh=interp1(alt, N, h) I get the error. When I use n0= interp1(alt, N, 0) I get an actual value.
I didnt think that using a variable instead of an actual value would matter if the variable had a number assigned to it.
Here is the error message:
Error in interp1 (line 152)
VqLite = F(Xqcol);
Error in ECE_6375_HW2_1 (line 45)
nh=interp1(alt,N,h);
댓글 수: 5
채택된 답변
Aditya Srikar
2023년 3월 2일
Hi Deanna
Consider this statement in while-loop
h= h+ deltaX* sqrt((angle^2)+(2*(nh+(h/Re)-n0)));
The value angle^2 is always non-negative.
But if 2*(nh+(h/Re) < n0, then (2*(nh+(h/Re)-n0) becomes negative.
When (2*(nh+(h/Re)-n0) is negative and (angle^2)+(2*(nh+(h/Re)-n0)) also becomes negative, then the whole expression sqrt((angle^2)+(2*(nh+(h/Re)-n0))) would not be having any real roots and it will result in imaginary values as roots of the equation.
That’s the reason why you are getting an error
Error using matlab.internal.math.interp1
Input coordinates must be real.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!