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 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Star Strider
2016-5-2
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 个评论
更多回答(1 个)
Image Analyst
2016-5-2
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!