operations on specific row
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Mitch Martelli
on 17 Nov 2011
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
More Answers (0)
See Also
Categories
Find more on Linear Regression 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!