I have values For example. At x=0, y=6.1; x=5; y=6.02, x=10; y=5.98, x=15, y=6.02. I want to plot like
this figure by Matlab. Could you help me ? Thank you very much

2 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 11 日
without datas nobody can interpret what you actually want
Tran Hoa
Tran Hoa 2018 年 10 月 11 日
For example. At x=0, y=6.1; x=5; y=6.02, x=10; y=5.98, x=15, y=6.02. Thank you

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

 採用された回答

madhan ravi
madhan ravi 2018 年 10 月 11 日
編集済み: madhan ravi 2018 年 10 月 11 日

0 投票

x = [ 0 : 5 : 15 ]
y = [ 6.1 6.02 5.98 6.02 ]
Secrenario = x
Location = y
plot(Secrenario,Location,'r')
xlim([0 50])
ylim([3 7])

6 件のコメント

Tran Hoa
Tran Hoa 2018 年 10 月 11 日
編集済み: Image Analyst 2018 年 10 月 11 日
But it does not work
madhan ravi
madhan ravi 2018 年 10 月 11 日
Check now
Tran Hoa
Tran Hoa 2018 年 10 月 11 日
Thank you very much. It works
Image Analyst
Image Analyst 2018 年 10 月 11 日
He meant xticks() instead of xlim(). This simply plots the data. If you want a smooth curve in between the points, use splines, like in my demo below.
madhan ravi
madhan ravi 2018 年 10 月 11 日
編集済み: madhan ravi 2018 年 10 月 11 日
Thank you @ sir Image Analyst keep inspiring as always:)
madhan ravi
madhan ravi 2018 年 10 月 11 日
you are welcome @Tran Hoa

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 10 月 11 日
編集済み: Image Analyst 2018 年 10 月 11 日

0 投票

To get a smooth curve line that between your training data, you'll have to use splines. See demo below (with your data), and attached with better data:
% Demo to show spline interpolation.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 12;
% Create data.
x = [ 0 : 5 : 15 ]
y = [ 6.1 6.02 5.98 6.02 ]
% Create the original knot points.
lengthX = length(x);
% Plot it and show how the line has sharp bends.
plot(x, y, '-sr', 'LineWidth', 2);
grid on;
xlabel('Scenario', 'FontSize', 20);
ylabel('Location', 'FontSize', 20);
title('Y vs. X', 'FontSize', 20);
xticks(0:5:max(x))
% ylim([3 7])
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Use splines to interpolate a smoother curve,
% with 10 times as many points,
% that goes exactly through the same data points.
samplingRateIncrease = 8;
newXSamplePoints = linspace(1, max(x), lengthX * samplingRateIncrease);
smoothedY = spline(x, y, newXSamplePoints);
% Plot smoothedY and show how the line is
% smooth, and has no sharp bends.
hold on; % Don't destroy the first curve we plotted.
plot(newXSamplePoints, smoothedY, '-ob');
title('Spline Interpolation Demo', 'FontSize', 20);
legend('Original Points', 'Spline Points');
% Mathworks Demo code from their Help
% x = 0:10;
% y = sin(x);
% xx = 0:.25:10;
% yy = spline(x,y,xx);
% plot(x,y,'o',xx,yy)
% Draw x axis
line(xlim, [0,0], 'Color', 'k', 'LineWidth', 2);
grid on;
legend('Original Points', 'Spline Points', 'Slope');
Your data:
My demo's data:

5 件のコメント

Tran Hoa
Tran Hoa 2018 年 10 月 11 日
Thank you very much
Tran Hoa
Tran Hoa 2018 年 10 月 11 日
編集済み: Tran Hoa 2018 年 10 月 11 日
I want to add another lines to have two lines in one diagram such as y2 = [ 7.1 7.02 6.98 7.02 ] beside y = [ 6.1 6.02 5.98 6.02 ]. How can I do. Thank you
madhan ravi
madhan ravi 2018 年 10 月 11 日
編集済み: madhan ravi 2018 年 10 月 11 日
hold on
plot(x,y2,'b')
Image Analyst
Image Analyst 2018 年 10 月 11 日
Put hold on before you plot the second curve
hold on;
plot(x, y2, '-', 'LineWidth', 3);
Tran Hoa
Tran Hoa 2018 年 10 月 11 日
Welldone. Thank you very much

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

カテゴリ

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

質問済み:

2018 年 10 月 11 日

コメント済み:

2018 年 10 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by