plot a certain x,y values from a large matrix

조회 수: 3 (최근 30일)
smo
smo 2015년 8월 13일
답변: Star Strider 2015년 8월 13일
hi,
i have a 4000rows(with x value from 1:4000) and 2 column (of y values) matrix. How can i plot x&y with, say, taking x value from x > 500 and x<2500 and their corresponding y values?
thank you very much.

답변 (2개)

Lessmann
Lessmann 2015년 8월 13일
You can use the colon operator to select a subset of your vector, like
plot(x(500:2500),y(500:2500))
  댓글 수: 1
smo
smo 2015년 8월 13일
편집: smo 2015년 8월 13일
Hi, thanks for that. I didn't make myself clear enough, I actually meant i don't know the index of x. (which means x are a set of numbers not in orders).
But I have did a small test myself and found the answer: first index x-values and then use the x and y value only for that index. I am putting my answer here incase it can help someone else.
for example:
x = [1:10];
y = [11:20];
idx = find (x>3 & x <7);
x_new = x(idx);
y_new = y(idx);
plot (x_new, y_new, '-o')

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


Star Strider
Star Strider 2015년 8월 13일
This works:
x = randi(4000, 1, 100); % Create Data
y = randi(99, 2, 100);
xp = x(x>500 & x<2500);
yp = y(:,(x>500 & x<2500));
figure(1)
plot(xp, yp, 'bp')
grid

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by