Data cursor showing color value
조회 수: 16 (최근 30일)
이전 댓글 표시
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
채택된 답변
Michael Abboud
2016년 9월 27일
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
추가 답변 (1개)
Gregory McFadden
2016년 9월 27일
댓글 수: 1
Michael Abboud
2016년 9월 27일
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:
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!