フィルターのクリア

operations on specific row

1 回表示 (過去 30 日間)
gianluca
gianluca 2011 年 11 月 17 日
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

採用された回答

Mitch Martelli
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
  1 件のコメント
gianluca
gianluca 2011 年 11 月 17 日
Hi Mitch,
your code works perfectly.
Thank you for your help and quickness!
Best regards
Gianluca

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by