convert plot(x,y) to plot(y(ind))

Hi,
I am trying to convert plot(x,y) to plot(y(ind)) So i am interesting in getting the indices of x which gives me y?
Thanks,

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 24일
편집: Azzi Abdelmalek 2015년 6월 24일

0 개 추천

Just do this
plot(y)

댓글 수: 6

Muhannad
Muhannad 2015년 6월 24일
편집: Azzi Abdelmalek 2015년 6월 24일
That will not work... my plot is
x = cumsum(hann(100));
y = linspace(-1,1,100);
plot(x,y);
I want to make it plot(y(ind))?
Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 24일
편집: Azzi Abdelmalek 2015년 6월 24일
Indices of x are from 1 to numel(x). Is this right?
Muhannad
Muhannad 2015년 6월 24일
Yes so the shape of the plot will be the same but the x axis will be different from 1 to 100.
Muhannad
Muhannad 2015년 6월 24일
plot(x,y) vs plot(y) is show in the attachment which is different from what I want. So what I want is plot(y(ind)) should look like plot(x,y) in other word I want the indices of y which will give me a plot similar in shape to plot(x,y).
Hope this is clear.
x = cumsum(hann(100));
y = linspace(-1,1,100);
plot(x,y);
idx=1:10:100
set(gca,'xtick',x(idx))
nxt=arrayfun(@num2str,idx,'un',0)
set(gca,'xticklabel',nxt)
Muhannad
Muhannad 2015년 6월 24일
can you show the final results in plot(y(ind))? as I need the indices and not the plot.

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

Purushottama Rao
Purushottama Rao 2015년 6월 24일

0 개 추천

g=interp1(y,x,0.5)
g gives you the x value corresponding to the given y value (0.5).
Use a for loop to find out the entire range.
Hope this is what you are looking for

댓글 수: 3

Muhannad
Muhannad 2015년 6월 24일
I am not sure if I am implementing it right, but a for look will be very slow as I am computing this for many values.
Purushottama Rao
Purushottama Rao 2015년 6월 24일
편집: Purushottama Rao 2015년 6월 24일
x = cumsum(hann(100));
y = linspace(-1,1,100);
plot(x,y);
for k=1:length(y)
g(k)=interp1(y,x,y(k));
end
The speed looks to be ok. Ofcourse i do not know whether you are using the same x and y or not.
Muhannad
Muhannad 2015년 6월 24일
so can you include another plot(y(ind)) which will give me the same shape as plot(x,y) but the x axis will be different and it will include the indices?

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

태그

질문:

2015년 6월 24일

댓글:

2015년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by