interp1() returns a plot with empty sections
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
about 11 hours 前
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!