Create multi slopes from a profile
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adi Purwandana
el 7 de Mayo de 2024
Comentada: Star Strider
el 8 de Mayo de 2024
Hello there,
Is there a possible way to create some slopes within a profile? My case: I have a profile containing some group of values separated by nans. My intention is how to create slopes for each group. So, since there are some groups in the profile, there will be some slopes which corresponds to each group.
Please find attached mat file for the data.
Cheers
0 comentarios
Respuesta aceptada
Star Strider
el 8 de Mayo de 2024
I am not certain what you want. This code performs a linear regression on the line clusters and then plots it for each of them.
Try this —
load('profiles_z_d.mat')
whos('-file', 'profiles_z_d.mat')
Q = [nnz(isnan(d_x1)) nnz(isnan(z))];
idx = ~isnan(d_x1);
startidx = strfind(idx, [0 1])+1;
stopidx = strfind(idx, [1 0]);
ssidx = [startidx; stopidx];
for k = 1:size(ssidx,2)
G{k,1} = d_x1(ssidx(1,k):ssidx(2,k));
G{k,2} = z(ssidx(1,k):ssidx(2,k));
B(:,k) = [G{k,1}; ones(size(G{k,1}))].' \ G{k,2}.';
end
% B
figure
plot(d_x1, z)
hold on
for k = 1:size(B,2)
rline = [G{k,1}; ones(size(G{k,1}))].' * B(:,k);
plot(G{k,1}, rline, '-r')
text(max(G{k,1})+0.1, max(rline), sprintf('y = %.2f \\cdotx% +.2f',B(:,k)), 'Horiz','left')
end
hold off
xlim([0 20])
title('All Data')
figure
plot(d_x1, z)
hold on
for k = 1:size(B,2)
rline = [G{k,1}; ones(size(G{k,1}))].' * B(:,k);
plot(G{k,1}, rline, '-r')
text(max(G{k,1})+0.1, max(rline), sprintf('y=%.2f\\cdotx%+.2f',B(:,k)), 'Horiz','left')
end
hold off
title('Selected Detail')
xlim([0 5])
ylim([390 415])
.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!