필터 지우기
필터 지우기

Create multi slopes from a profile

조회 수: 2 (최근 30일)
Adi Purwandana
Adi Purwandana 2024년 5월 7일
댓글: Star Strider 2024년 5월 8일
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

채택된 답변

Star Strider
Star Strider 2024년 5월 8일
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
Adi Purwandana
Adi Purwandana 2024년 5월 8일
편집: Adi Purwandana 2024년 5월 8일
Bravo, that's exactly what I want. Thank you very much!
Star Strider
Star Strider 2024년 5월 8일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by