Plot a scatter graph with points coloured according to values looked up in a cell array

2 views (last 30 days)
Hi,
I need to process many 3 column Data files with element, atom x positions and atom y positions. Such as
C 0 0
C 0 1
C 1 0
O 1 1
H 2 1
etc.
As an added functionality I want to be able to sketch a quick scatter graph of the data, with elements correctly coloured. I.e. Carbon in black etc.
My current solution is:
Elements = Data{1,1};
AtomX = Data{1,2};
AtomY = Data{1,3};
contourf(x_range,y_range,Results);
hold on
gscatter(AtomX,AtomY,Elements,'krw');
xlabel('x');
ylabel('y');
which ensures different elements are in different colours, with the first element to appear in the file coloured black (k), second element red (r) etc. This however relies on me knowing in advance the order and range of all the elements in all the data files.
I've been trying to create a "colour map" file which can permanently map element "C" to black, "O" to red, "H" to white etc. And then input a formula into the scatter function that can lookup the element of a particular point to assign the correct colour. However I can't quite get my head over how exactly to do it. Any suggestions? Many thanks

Answers (0)

Community Treasure Hunt

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

Start Hunting!