How can i write a code like this?

1 visualización (últimos 30 días)
Volkan Yangin
Volkan Yangin el 12 de Oct. de 2016
Editada: dpb el 13 de Oct. de 2016
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.

Respuesta aceptada

dpb
dpb el 12 de Oct. de 2016
Editada: dpb el 13 de Oct. de 2016
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 comentarios
Volkan Yangin
Volkan Yangin el 12 de Oct. de 2016
Thank you dbp, this code works. :) But, is there any way to get the datas of this line?
dpb
dpb el 13 de Oct. de 2016
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.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by