Clear Filters
Clear Filters

Create multi slopes from a profile

2 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 8 May 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 Comments
Adi Purwandana
Adi Purwandana on 8 May 2024
Edited: Adi Purwandana on 8 May 2024
Bravo, that's exactly what I want. Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!