Interp1 error VqLite = F(Xqcol)
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Aditya Srikar
on 2 Mar 2023
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 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!