operations on specific row
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I've a for example a 5x3 matrix
2015 52 7
2015 53 12
2015 54 20
3096 77 7
3096 83 11
and I want apply the function p = polyfit(x,y,1) to third (independent variable) and second (dependent variable) column. Moreover I want apply the regressions to data which have the same value in the first column. In this case a first regression on the first 3 data and a second regression on the last 2 data. How can I define this criteria?
Thanks
Gianluca
0 个评论
采纳的回答
Mitch Martelli
2011-11-17
Hi,
for your first question you can use :
p = polyfit(A(:,3),A(:,2),1);
Pay attention to use one like degree .
For the second question the following code should work , but i dont know if there is a way to dont use for loop:
b = unique(A(:,1));
degree=1;
p=zeros(size(b,1),degree+1);
for i=1:size(b,1)
ind = find(A(:,1)==b(i));
p(i,:) = polyfit(A(ind,3),A(ind,2),1);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!