# Scatter Plot only Non-Zero Set of Points

36 views (last 30 days)
CMatlabWold on 5 May 2020
Commented: CMatlabWold on 6 May 2020
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,
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)
CMatlabWold on 5 May 2020
lol I get it

Sindar on 5 May 2020
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
CMatlabWold on 6 May 2020
You are right. Thank you!