Choosing middle points in discrete function

1 回表示 (過去 30 日間)
Zine
Zine 2014 年 2 月 19 日
回答済み: Zine 2014 年 2 月 21 日
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 Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by