I want to plot trend line (and want to record its slop) to multiple figures

2 次查看(过去 30 天)
Good Day, I have almost 50,000 points single column data. I divided it into 6 equal parts, calculated rms for each part, and want to plot trending curve of each part. For polyfit, I don't have values of x. I don't know why, but lsline is also not showing anything.
T = 6*fix(numel(V1)/6);
six_parts = reshape(V1(1:T),[],6);
for i = 1:6
sp1= six_parts(:,i);
P1 = sp1;
Pa1 = WinSize*fix(numel(P1)/WinSize); %numel(V1) counts number of elements in V1. it is numeL, not 1(one); fix(A) will round the number to nearest intiger
rP1 = rms(reshape(P1(1:Pa1),WinSize,[]),1);
figure;
% h1 = lsline
plot (rP1);
tmean(i) = trimmean(rP1,10)
xlswrite('abc',tmean);
Any suggestion is welcome
  3 个评论
UET Hussain
UET Hussain 2018-2-23
i tried this, but polyfit is not giving any output..... (means no trend line has been shown)
if true
T = 6*fix(numel(N)/6);
six_parts = reshape(N(1:T),[],6);
for i = 1:6
sp1= six_parts(:,i);
x= 1:length(sp1);
x=x';
P1 = sp1;
Pa1 = WinSize*fix(numel(P1)/WinSize); %numel(V1) counts number of elements in V1. it is numeL, not 1(one); fix(A) will round the number to nearest intiger
rP1 = rms(reshape(P1(1:Pa1),WinSize,[]),1);
figure;
plot (sp1);
polyfit(x,sp1,1);
tmean(i) = trimmean(sp1,10)
xlswrite('abc',tmean);
end
am i putting polyfit at right position????
KSSV
KSSV 2018-2-23
polyfit gives you slope and y-intercept of your straight line.....using these you need to draw you line.....you are not doing that....

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2018-2-23
Use polyfit like below to draw a line later:
x = linspace(0,4*pi,10);
y = sin(x);
% Use polyfit to fit a line to the points
p = polyfit(x,y,1);
% Evaluate the polynomial on a finer grid and plot the results.
x1 = linspace(0,4*pi);
y1 = polyval(p,x1);
figure
plot(x,y,'o')
hold on
plot(x1,y1)
hold off
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by