필터 지우기
필터 지우기

How can i write a code like this?

조회 수: 1 (최근 30일)
Volkan Yangin
Volkan Yangin 2016년 10월 12일
편집: dpb 2016년 10월 13일
Hi everbody,
I want to draw a linear change between two datas which have a difference as %5. For ex:
Datas:
-0,012 -0,024 -0,03 -0,02 -0,02 -0,01 -0,02 -0,03 -0,03 -0,05 -0,065 -0.06 -0.1
How can i create a linear change from -0.012 to -0.065 and from -0.065 to -0.1?
There are 512 datas and i can't correctly use if command. I use this command with first data, but i have to evaulate all of the datas because; for ex there may be a %5 difference between 126. and 225. datas.

채택된 답변

dpb
dpb 2016년 10월 12일
편집: dpb 2016년 10월 13일
Well, this may be a challenge depending on what you're really wanting, but as a starting point...
>> y=[ -0.012 -0.024 -0.03 -0.02 -0.02 -0.01 -0.02 -0.03 -0.03 -0.05 -0.065 -0.06 -0.1];
>> plot(y)
>> ix=find(abs(y-y(1))>0.05,1); % find first point that's >5% difference
>> [ix y(ix)] % what'd we find??? Looks like it...
ans =
11.0000 -0.0650
>> hold on,hL=line([1 ix],[y(1) y(ix)],'color','r'); % draw the line
>> find(abs(y(ix:end)-y(ix))>0.05,1)
ans =
Empty matrix: 1-by-0
>> max(abs(y(ix:end)-y(ix)))
ans =
0.0350
>>
Now you've hit a snag; your relative difference isn't met so the next attempt fails. So now is it the maximum difference or the last point or what?
Anyway, should give you some starting points to work from...just iterate over the pieces, remembering to keep adding the offset of the initial starting point in subsequent find results to refer to the position in the original vector or shorten the vector to match.
  댓글 수: 2
Volkan Yangin
Volkan Yangin 2016년 10월 12일
Thank you dbp, this code works. :) But, is there any way to get the datas of this line?
dpb
dpb 2016년 10월 13일
Not sure I understand the question/problem...in the first segment it's the [ix y(ix)] pair; simply save those values as you progress down the initial vector however you choose to solve the issue regarding the problem the above runs into with the 0.05 magnitude difference.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by