Trimming a curve - how to find nearest number and replace
2 ビュー (過去 30 日間)
古いコメントを表示
I have the x and y coordinates for a bathymetric curve eg...
x y
0 1.36
0.03 -0.92
0.13 -1.68
1.69 -3.72
6.63 -3.35
9.18 -3.36
20.03 -3.26
31.75 -2.93
40.15 -1.70
46.21 0.10
69.97 2.26
I would like to trim this curve to a certain level line with at y=-0.15 and x from 0 to 45 I need to both replace the first coordinate with (0,-0.15) and make the final coordinate (45,-0.15) removing any x,y values greater than this.
I have this for a large number of data sets so of course a loop would be preferential but I cannot work out how to do these operations through code alone. The image below might clarify what I mean a little more, though it was made with different numbers.
Thanks in advance for any help
0 件のコメント
採用された回答
Greg Dionne
2017 年 3 月 30 日
Try:
myLimit = -0.15;
iFirst = find(y<myLimit, 1, 'first');
iLast = find(y<myLimit, 1, 'last');
xdesired = x(iFirst:iLast);
ydesired = y(iFirst:iLast);
plot(x, y);
hold on
plot(xdesired, ydesired);
legend('Original','Trimmed')
3 件のコメント
Greg Dionne
2017 年 3 月 31 日
OK. good.
For the concatenation I would probably do something like:
% use "," instead of ";" if xdesired and ydesired are row vectors
xdesired = [0; xdesired; 45];
ydesired = [mylimit; xdesired; mylimit];
Glad you got past this.
-G
その他の回答 (1 件)
Image Analyst
2017 年 3 月 30 日
The data you supplied does not look like your plots. But to clamp data to some level, try this:
xy = [...
0 1.36
0.03 -0.92
0.13 -1.68
1.69 -3.72
6.63 -3.35
9.18 -3.36
20.03 -3.26
31.75 -2.93
40.15 -1.70
46.21 0.10
69.97 2.26];
x = xy(:, 1);
y = xy(:, 2);
subplot(2, 1, 1);
plot(x, y, 'b-');
grid on;
yClamped = y; % Initialize
clampLevel = 0.15;
yClamped(y>clampLevel) = clampLevel; % Do the clamping
subplot(2, 1, 2);
plot(x, yClamped, 'b-');
grid on;
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!