Effacer les filtres
Effacer les filtres

Create multi slopes from a profile

2 vues (au cours des 30 derniers jours)
Adi Purwandana
Adi Purwandana le 7 Mai 2024
Commenté : Star Strider le 8 Mai 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

Réponse acceptée

Star Strider
Star Strider le 8 Mai 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')
Name Size Bytes Class Attributes d_x1 1x883 7064 double z 1x883 7064 double
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 commentaires
Adi Purwandana
Adi Purwandana le 8 Mai 2024
Modifié(e) : Adi Purwandana le 8 Mai 2024
Bravo, that's exactly what I want. Thank you very much!
Star Strider
Star Strider le 8 Mai 2024
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by