interp1() returns a plot with empty sections
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Star Strider
circa 11 ore fa
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 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!