Choosing middle points in discrete function

1 次查看(过去 30 天)
I have a set of experimental data y=f(x), this set looks like a discrete function means for y=a there are several corresponding x, the overall variation is sin(x) like shape like steps going up and down along with x axis. My question is, can any one help me to remove the repeated y from each step and create another set newy=f(newx) that passes through the middle point of each step, so then I will plot both as plot(x,y,'x',newx,newy) and I have the plot(newx,newy) passing exactly in the middle point of each step; thanks in advance and sorry for the long explanation
  3 个评论
mohammed
mohammed 2014-2-19
can you give a simple example or can post your result means of some image?
Zine
Zine 2014-2-19
see attached hand drawing where the black lines are my original set of data, and the blue stars are the desired new set and the red line is the link between new set points, I did not put my data because it is huge array of data, in my function it takes the last point of each step but I need the middle point,(x points in one step is variable from 1 to around 60)

请先登录,再进行评论。

采纳的回答

Zine
Zine 2014-2-21
The problem is solved by introducing a counter in the algorithm that calculates the number of repeated data and than divide that number by two as follows
function [ nx,ny ] = nrp( xdata,ydata)
%UNTITLED Summary of this function goes here % Detailed explanation goes here
imax=length(xdata);
count=1;
j=1;
for i=1:imax-1
if ydata(i)==ydata(i+1)
count=count+1;
else
midcount=int16(count/2);
nx(j)=xdata(i-midcount+1);
ny(j)=ydata(i-midcount+1);
count=1;
j=j+1;
end
end
nx=[nx xdata(length(xdata))];
ny=[ny ydata(length(ydata))];
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by