Create multi slopes from a profile
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
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')
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!