how to fit different lines for scatter points from specific categorical data?

1 回表示 (過去 30 日間)
SGL
SGL 2019 年 9 月 18 日
編集済み: Adam Danz 2019 年 9 月 23 日
I got a table like this:
PLACE O18 D
Place3 -9.17 -71.68
Place2 -8.24 -61.47
Place2 -9.79 -70.24
Place3 -5.93 -62.67
Place2 -4.58 -29.3
Place1 -4.44 -26.5
Place1 -4.07 -28.4
...
which I imported like three column vectors: place, oxygen18, deuterium respectively.
plotted using
gscatter(oxygen18,deuterium,place)
and fitted a general tendency line
ft = fittype( 'poly1' );
[fit_line, gof] = fit( oxygen18, deuterium, ft);
now I would like fit a line 'oxygen18' vs 'deuterium' for each group entry in the vector 'place', i.e. 'oxigen18' vs 'deuterium' in Place1 and then for Place2 next for Place3, and so on.
How it could be achieved?.
Thanks.

採用された回答

Adam Danz
Adam Danz 2019 年 9 月 18 日
編集済み: Adam Danz 2019 年 9 月 23 日
Easiest way is to do it in a loop.
placeUnq = unique(place); %all unique place values
fit_line_groups = cell(numel(placeUnq),1); %store results
gof_groups = fit_line_groups; %store results
% loop through each unique place
for i = 1:numel(placeUnq)
[fit_line_groups{i}, gof_groups{i}] = fit(oxygen18(place==placeUnq(i)), deuterium(place==placeUnq(i)), ft);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by