Line two is upside down as compared to line one
And as shown above,
I want to make Line 2 the same as Line 1.
The picture above is my guess.
Do you have any mathematical methods or other methods?
My English is not good sorry.

 採用された回答

Image Analyst
Image Analyst 2019 年 12 月 25 日

0 投票

You can fit a line through curve 1. Then subtract the max of curve two and add the fitted line to it.
coefficients = polyfit(x1, y1, 1); % Fit a line.
% Get the line at locations where you have x2.
line1 = polyval(coefficients, x2);
% Find the max of curve 2.
y2max = max(y2);
% Make output curve (curve 3)
y3 = y2 - y2max + line1; % Tilt curve 2 upwards at the slant of curve 1
If you need more help, please attach the two curves in a .mat file with the paper clip icon.

6 件のコメント

Kang Min Kim
Kang Min Kim 2019 年 12 月 25 日
Thanks for the reply But I want to adopt this answer, but I get an error. What should I do?
Kang Min Kim
Kang Min Kim 2019 年 12 月 25 日
編集済み: Image Analyst 2019 年 12 月 25 日
>> t = 0:300;
dailyFluct = gallery('normaldata',size(t),2);
sdata = cumsum(dailyFluct) + 20 + t/100;
figure
plot(t,sdata);
legend('Original Data','Location','northwest');
xlabel('Time (days)');
ylabel('data');
I'd like to make this graph the same as the question I posted.
I don't know how to turn the graph upside down.
Please excuse me for that. Thank you.
Image Analyst
Image Analyst 2019 年 12 月 25 日
Your code makes this plot:
0000 Screenshot.png
Tell me which is curve 1 (the top one), which is curve 2 (the middle one), and then I can tell you how to make curve 3 (the bottom one).
Kang Min Kim
Kang Min Kim 2019 年 12 月 25 日
Curve 2 is the upside down of that curve
I don't know how to do the upside down, sorryK-049.jpg
This is curve 2
But this is just a change of axis
I'm not inverting the data(value)
I do not know how to do upside down data(value)
sorry
Image Analyst
Image Analyst 2019 年 12 月 25 日
Do you mean something like this:
clc; % Clear the command window.
clear all; % Including global variables.
close all force; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
filebrowser;
format short g;
format compact;
fontSize = 14;
t = 0:300;
dailyFluct = gallery('normaldata',size(t),2);
sdata = cumsum(dailyFluct) + 20 + t/100;
figure
subplot(1, 3, 1);
plot(t, sdata, 'b-', 'LineWidth', 2); % Plot original y data
% legend('Original Data','Location','northwest');
grid on;
xlabel('Time (days)');
ylabel('data');
title('Original data', 'FontSize', fontSize);
coefficients = polyfit(t, sdata, 1); % Fit a line.
% Get the line at locations where you have x2.
line1 = polyval(coefficients, t);
hold on;
plot(t, line1, 'r-', 'LineWidth', 2); % Plot line
legend('original y', 'Line through y');
% Find the max of curve 1.
y1min = sdata(1);
% Make the upside down data.
y2 = -sdata;
subplot(1, 3, 2);
plot(t, sdata, 'b-', 'LineWidth', 2); % Plot original y data
hold on;
plot(t, line1, 'r-', 'LineWidth', 2); % Plot line
plot(t, y2, 'c-', 'LineWidth', 2); % Plot upside down (negative) data
grid on;
title('Upside down data', 'FontSize', fontSize);
% Shift y2 upwards so that the first points start at the same y location.
y2 = y2 + 2 * y1min;
plot(t, y2, 'm-', 'LineWidth', 2); % Plot line
legend('original y', 'Line through y', 'Negative y', 'Negative y shifted upwards');
% Make output curve (curve 3)
y3 = 2 * line1 + y2 - 2 *y1min; % Tilt curve 2 upwards at the slant of curve 1
subplot(1, 3, 3);
plot(t, sdata, 'b-', 'LineWidth', 2); % Plot original y data
hold on;
plot(t, line1, 'r-', 'LineWidth', 2); % Plot line
plot(t, y3, 'm-', 'LineWidth', 2);
grid on;
title('Both original and Upside down data', 'FontSize', fontSize);
legend('original y', 'Line through y', 'y3, tilted upwards');
0000 Screenshot.png
Kang Min Kim
Kang Min Kim 2019 年 12 月 30 日
thank you for your answer
I want to replace line through y with the moving average(30days) of original y.
I would appreciate it

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by