Hi,
I suppose... Let's say, once you make two tables of values and you decide create a scatter plot, where the row values of one table is plotted against the row values the other... how can you use scatter to plot only the non-zero points in the tables?
For instance,
I had:
x1 = tt5{:,6}
y1 = ss5{:,6}
scatter(x1,y1,'b')
hold on
where
ss5 column 6:
0
1
0
0
1
0
0
0
tt5 column 6:
0
7
6
5
18
6
4
5
So, I would only want to plot (7,1) and (18,1)

댓글 수: 6

Rik
Rik 2020년 5월 5일
Your code would be a lot easier to read if you had written it very differently. If you find yourself having more than two nearly identical blocks of code you should consider making it a loop, or use a function.
You should not be using numbered variables like this. If you had put the results in an array it would probably be a lot easier to solve your question.
CMatlabWold
CMatlabWold 2020년 5월 5일
I edited the question. But, I agree.
Rik
Rik 2020년 5월 5일
If you edit away code, can you at least not remove the formatting?
CMatlabWold
CMatlabWold 2020년 5월 5일
편집: CMatlabWold 2020년 5월 5일
Do you want me to answer that as "Yes sir?" or "Yes, Boss."
Rik
Rik 2020년 5월 5일
Either will do ;)
It is just a bit frustrating to apply formatting to your question, and then having to do it again because you removed everything including the formatting. The edit controls are right there when you edit you posts, please use them.
CMatlabWold
CMatlabWold 2020년 5월 5일
lol I get it

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

 채택된 답변

Sindar
Sindar 2020년 5월 5일

0 개 추천

Here's how to do this with a small example script:
% create a 5x2 array of random integers 0-5 for both x and y
x = randi([0 5],5,2);
y = randi([0 5],5,2);
% identify indices where both x and y are not zero
idx = (x ~= 0) & (y ~= 0);
% plot only these
scatter(x(idx),y(idx))
If this doesn't work with your code, please work to simplify it as Rik suggests

댓글 수: 5

CMatlabWold
CMatlabWold 2020년 5월 5일
Hmm... Maybe I made this too much of a loaded question (the code could be better, of course). I should have skipped the code and included only the scatter information. So, I will edit my question...
I suppose... Let's say, once you make two tables of values and you decide create a scatter plot, where the row values of one table is plotted against the row values the other... how can you use scatter to plot only the non-zero points in the tables?
For instance,
scatter(x1,y1,'b')
hold on
where
x1 = tt5{:,6}
y1 = ss5{:,6}
ss5 column 6:
0
1
0
0
1
0
0
0
tt5 column 6:
0
7
6
5
18
6
4
5
So, I would only want to plot (7,1) and (18,1)
x1 = tt5{:,6};
y1 = ss5{:,6};
% identify indices where both x1 and y1 are not zero
idx = (x1 ~= 0) & (y1 ~= 0);
% plot only these
scatter(x1(idx),y1(idx),'b')
CMatlabWold
CMatlabWold 2020년 5월 5일
The zeros do not go away:
Sindar
Sindar 2020년 5월 5일
편집: Sindar 2020년 5월 5일
look at the plot, those are 1's. It will look better if you change the ylim:
% get current limits
yl=ylim();
% set new bottom limit to 0
ylim([0 yl(2)])
CMatlabWold
CMatlabWold 2020년 5월 6일
You are right. Thank you!

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

추가 답변 (0개)

카테고리

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

제품

질문:

2020년 5월 5일

댓글:

2020년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by