I dont know how to plot more than one regressions in one plot, like the picture i did in excel. I tried basic fitting tool but could not success, and i have look at multiple regression but could not understand becaus of no example. Thank for any help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Akzeptierte Antwort
Star Strider
am 2 Mai 2016
Something like this should work:
x = 1:10;
y1 = rand(1, 10);
y2 = rand(1, 10);
DM = [x', ones(length(x),1)]; % Design Matrix
B1 = DM \ y1'; % Estimate Parameters Of ‘y1’ Fit
B2 = DM \ y2'; % Estimate Parameters Of ‘y2’ Fit
y1_fit = DM*B1; % Calculate Fit For ‘y1’
y2_fit = DM*B2; % Calculate Fit For ‘y2’
figure(1)
plot(x, y1, '.b', x, y2, '.r') % Plot Data
hold on
plot(x, y1_fit, '--b', x, y2_fit, '--r') % Plot Fitted Regression Lines
hold off
grid
2 Kommentare
Weitere Antworten (1)
Image Analyst
am 2 Mai 2016
If you want a polyfit() example, see attached. Like Star showed, you just do the fit first for the first set of data, and plot that fit, then call hold on, and do it again for the second set of data.
Siehe auch
Kategorien
Mehr zu Regression 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!