Data cursor showing color value
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Gregory McFadden
le 20 Sep 2016
Commenté : Michael Abboud
le 27 Sep 2016
Is there a way to get the data cursor to list the X,Y,Z coordinates and the value from the colorbar in a 3d scatter plot with the dots colored by a 4th column vector?
the default data cursor gives only X,Y,Z.
thanks Greg
0 commentaires
Réponse acceptée
Michael Abboud
le 27 Sep 2016
While there is no property of a data cursor which will provide this data, it is certainly possible using callback functions. Fortunately, you can access these functions very easily:
-
1. Open your plot, and create a data cursor
2. Right-click on the plot, and click “Edit Text Update Function”
3. Insert the following lines of code at the end of function, and save to your desktop
% search for the correct data point
xIdx = find(event_obj.Target.XData == pos(1));
yIdx = find(event_obj.Target.YData == pos(2));
zIdx = find(event_obj.Target.ZData == pos(3));
% select single data point, and find value
idx = intersect(intersect(xIdx,yIdx),zIdx);
value = event_obj.Target.CData(idx(1));
% add to the data cursor text
output_txt{end+1} = sprintf('Value: %d',value);
4. If the change has not taken effect, then right-click on the plot once again, and click “Select Text Update Function”, and select the new callback function you have created
5. Select a new data point in your scatter plot, and open the Colorbar if desired
-
Note: this provides the scalar value of your data, rather than an RGB color. You could find the color by scaling your data to the Parula (or Jet) colormap, and indexing into that colormap.
0 commentaires
Plus de réponses (1)
Gregory McFadden
le 27 Sep 2016
1 commentaire
Michael Abboud
le 27 Sep 2016
If you are using a version of MATLAB such as R2014a or earlier, then graphics generally work a bit differently from newer releases. You can refer to the following link for more information about the graphics changes in MATLAB R2014b:
-
If your version of MATLAB is pre-R2014b, try replacing the terms such as “event_obj.Target.XData” with the following:
>> get( get(event_obj, 'Target'), 'XData')
And then replace the specific line:
>> value = event_obj.Target.CData(idx(1));
With the following:
>> CData = get( get(event_obj, 'Target'), 'CData');
>> value = CData(idx(1));
Also note that I am using an example from the "scatter3" documentation page to test my solution. Perhaps see if you can get it working with the 3rd example, "Vary Marker Color", and then generalize to your own code. You can find the "scatter3" documentation page below:
Voir également
Catégories
En savoir plus sur Orange dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!