getting the middle value of two curves ??

조회 수: 6 (최근 30일)
Kang Min Kim
Kang Min Kim 2020년 1월 2일
답변: Mustafa Abu-Mallouh 2020년 1월 2일
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
I want to get the middle value between ORINAL Y and line through Y.
What should I do?
thank you
  댓글 수: 3
Kang Min Kim
Kang Min Kim 2020년 1월 2일
its original Y and line through y in first graph(original data)
thank you
Matt J
Matt J 2020년 1월 2일
편집: Matt J 2020년 1월 2일
But you were asked to explain what "middle value" means. It is terminology that we don't recognize.

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

채택된 답변

Mustafa Abu-Mallouh
Mustafa Abu-Mallouh 2020년 1월 2일
If you're looking for a line that is equidistant from original y and line through y values for any given x value, you can take the average of the y-values of each line as below
meanline = mean([sdata ; line1],1);
If that does not answer your question, please clarify what you mean by middle value as others have already stated.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by