interp1() returns a plot with empty sections
13 views (last 30 days)
Show older comments
I am trying to use the interp1() function to first, plot a continuous graph between a variable and time. Then I want to use the plot to look up the value of the variable at every instant. However, my plot appears to have empty sections, which is probably why I get NaN errors in my calculations. I attached my excel file also.
grade_data = readmatrix('grade.xlsx'); % reads the excel file
t_grade_raw = grade_data(:, 1)'; % Extract Time (transpose to row vector)
grade_raw = grade_data(:, 2)'; % Extract Grade (transpose to row vector)
% Interpolating to plot
grade_interp = interp1(t_grade_raw, grade_raw, t, 'linear');
% Safety: Replace any remaining NaNs with 0
grade_interp(isnan(grade_interp)) = 0;
% Graphing
plot(t, grade_interp, 'r-', 'LineWidth', 1.5);
0 Comments
Answers (1)
Star Strider
about 10 hours ago
The 't' variable seems to be undefined, and we do not have 'grade.xlsx' to work with.
If 't' is beyond the limits of 't_grade_raw', the result will be NaN unless the 'extrap' flag is set, , allowing interp1 to extrapolate.
0 Comments
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!