필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by