フィルターのクリア

how to plot a mean line in a plot

4 ビュー (過去 30 日間)
Alina Abdikadyr
Alina Abdikadyr 2023 年 2 月 27 日
回答済み: Star Strider 2023 年 2 月 27 日
Hello everyone!
Could you please help me with a plot. When I plot a mean v, it plots differently as 0. I need to mean line to be at the same angle as my fluctuations.
My code is:
clear all; close all;
N=100;
t = (0:N);
t1=(0:N-1);
t2=(0:N-1);
tt = rand(1,N) * 2 * pi;
ang = rand(1,N) * 2 * pi;
amp_u = 2;
amp_v = 1;
amp_w = 0.5;
u_mean=2;
v_mean=1;
w_mean=1;
u1 = amp_u.*sin(100*t2)+u_mean;
v1 = sin(ang) .* amp_v+v_mean;
w1=sin(ang) .* amp_w+w_mean;
u = cumsum([2, u1]);
x(1:N)=mean(u1);
v = cumsum([2, v1]);
w = cumsum([2, w1]);
figure(1); plot(t,u);
hold on
plot(t1,x);
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 2 月 27 日
Mean will be a scalar, constant value and it plots accordingly as well.
"When I plot a mean v ..."
You are not plotting v in your code above.
"I need to mean line to be at the same angle as my fluctuations."
Can you explain what do you mean by this? Perhaps a figure will be more helpful.

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

採用された回答

Star Strider
Star Strider 2023 年 2 月 27 日
I need to mean line to be at the same angle as my fluctuations.
You apparently want the linear regression of ‘u1’ as a function of ‘t1’ not the mean of ‘u1’.
Try this —
% clear all; close all;
N=100;
t = (0:N);
t1=(0:N-1);
t2=(0:N-1);
tt = rand(1,N) * 2 * pi;
ang = rand(1,N) * 2 * pi;
amp_u = 2;
amp_v = 1;
amp_w = 0.5;
u_mean=2;
v_mean=1;
w_mean=1;
u1 = amp_u.*sin(100*t2)+u_mean;
v1 = sin(ang) .* amp_v+v_mean;
w1=sin(ang) .* amp_w+w_mean;
u = cumsum([2 u1]);
% x(1:N)=mean(u1);
B = [t(:) ones(size(t(:)))] \ u(:); % Linear Regression Parameters
x = [t2(1) 1; t2(end) 1] * B; % Linear Regression Evaluation
v = cumsum([2, v1]);
w = cumsum([2, w1]);
figure(1)
plot(t,u)
hold on
plot(t1([1 end]),x)
ylim([0 max(ylim)])
While I am thinking about it, do you have any thoughts on my Answer to plot a graph from user input?
.

その他の回答 (2 件)

Askic V
Askic V 2023 年 2 月 27 日
Perhaps, you can use this code:
plot(t1,x.*t1);

Sylvain
Sylvain 2023 年 2 月 27 日
Your question is not veary clear, but I think you want to plot:
plot(t,mean(u1)*t)

カテゴリ

Help Center および File ExchangeSupport Vector Machine Regression についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by