How to add a trendline with ployfit

3 views (last 30 days)
Sean St Cyr
Sean St Cyr on 13 Nov 2020
Answered: SaiDileep Kola on 16 Nov 2020
I have the following code, and I am trying to put a trendline to the graph that it outputs, How would i do that with polyfit to this code?
if strcmp(choice,'Detail')
[q,tf] = listdlg("PromptString",'Choose a material', "ListString", Information.Material); %prompts the list dialoug box
if tf == 1
x0 = (q*2)-1;
y0 = q*2;
for D = 1:1:length(q)
plot(Data(x0(D),2:end),Data(y0(D),2:end),Information.Format{q(D)}) %plot data
grid on
hold on
lnd{L} = Information.Material{q(D)};
L = L+1;
end
xlim([0 10]) %Sets x axis from 0-10
ylim([0 100]) %Sets y axis from 0-100
xlabel('Time (t) [min]'); %X-axis label
ylabel('Temperature difference (T) [°C]'); %Y-axis label
title('Detailed Plot of Selected Materials'); %Title of graph
end
if tf == 0
error('PLEASE MAKE A SELECTION') % if there is no choice then produce the error
end
end

Answers (1)

SaiDileep Kola
SaiDileep Kola on 16 Nov 2020
Hi Sean,
you can have a look over it.

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!