# Plot out of cell array with attributes

4 views (last 30 days)
Maier on 18 Nov 2016
Commented: Maier on 23 Nov 2016
Hi, at first here is my code:
x = zeros(1979,1);
y = zeros(1979,1);
B = cell(1979,1);
for i = 1 : 1979
x(i) = i;
y(i) = i;
if i > 150
B(i,1) = {'bs'};
else
B(i,1) = {'ks'};
end
end
plot(x,y,B(:));
so the x vector contains my x-coordinates and the y-vector my y-coordinates. Now for example I want to plot the first 150 as a blue square and the others should be a black square.
I now that I can do it with a for-loop but in my real case the attributes depend on a a lot of things. So I want to create a cell array which contains the color and the appearance of the marker for each coordinates and to plot it automatically without a for-loop.
I hope you understand what I want to do :)
Maier on 23 Nov 2016
Ok anyway thank you.
I'm writing a script to visualize the power flow solutions of an european electrical transmission grid. Every point is a substation of the grid and the context menu contains Information about it (e.g. voltage, name,...) which is individual for every point. Also the markerstyle and color depends from point to point. I'm doing it with a context menu because it gets a lot messy if I would do it any other way.

Nick Counts on 19 Nov 2016
Edited: Nick Counts on 19 Nov 2016
I think you are looking for gscatter, which allows you to define a "group vector" and then define different styles for each group. It works sort of like logical indexing. There is good documentation, but here is an example:
x = 1:1979;
y = 1:1979;
% Make the group vector.
% The first 150 points are group 1
% The rest are group 2
group(1:150) = 1;
group(151:1979) = 2;
% The colors are assigned blue to 1, black to 2
% The marker styles are square to 1, circle to 2
gscatter(x, y, group, 'bk', 'so')
Hope this helps!
##### 2 CommentsShowHide 1 older comment
Image Analyst on 23 Nov 2016
If you want to control a whole bunch more stuff on a data point-by-data point basis, you're going to have to plot it one data point at a time.