Clear Filters
Clear Filters

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

2 views (last 30 days)
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 Comments
UET Hussain
UET Hussain on 23 Feb 2018
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 on 23 Feb 2018
polyfit gives you slope and y-intercept of your straight line.....using these you need to draw you line.....you are not doing that....

Sign in to comment.

Accepted Answer

KSSV
KSSV on 23 Feb 2018
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!