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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Adam Danz
Adam Danz el 18 de Sept. de 2019
Editada: Adam Danz el 23 de Sept. de 2019
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

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by