- Filter the data to include only points where "y" is greater than -1.7.
- Perform a linear fit on the selected data.
- Plot the original data, selected data, and the fitted line.
- Display the slope of the fitted line.
To curve fit the selected data from the plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i want to linear fit the selected data from the given plot and calculate the slope of the fitted data , i first selected the data above y=-1.7 using ylim command and then applied polyfit command on to the selected data but I am just getting NaN as result and no plot.can anyone please provide a solution to this problem.

0 Kommentare
Antworten (1)
Nipun
am 6 Jun. 2024
Bearbeitet: Nipun
am 6 Jun. 2024
Hi Divita,
I understand that you want to fit a line to the selected data from your plot and calculate the slope. Here is the updated MATLAB code:
% Assuming x and y are your data vectors
x = log((T - Tc) / Tc); % Example x data
y = log(V); % Example y data
% Select data above y = -1.7
selected_indices = y > -1.7;
x_selected = x(selected_indices);
y_selected = y(selected_indices);
% Perform linear fit
p = polyfit(x_selected, y_selected, 1);
% For more information on polyfit, refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/polyfit.html
% Extract slope and intercept
slope = p(1);
intercept = p(2);
% Plot original data
figure;
plot(x, y, '*');
% For more information on plot, refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/plot.html
hold on;
% Plot selected data
plot(x_selected, y_selected, 'or');
% Plot the fitted line
y_fit = polyval(p, x_selected);
plot(x_selected, y_fit, '-k');
% Add labels and title
xlabel('Log((T-Tc)/Tc)');
ylabel('Log(V)');
title('Linear Fit to Selected Data');
legend('Original Data', 'Selected Data', 'Fitted Line');
% Display slope
disp(['Slope: ', num2str(slope)]);
This code will:
For more information on disp, refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/disp.html
For more information on polyval, refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/polyval.html
Hope this helps.
Regards,
Nipun
0 Kommentare
Siehe auch
Kategorien
Mehr zu Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!