Round values of one datatip row
조회 수: 10 (최근 30일)
이전 댓글 표시
I have the following code:
a = [1.002, 2.006, 3.01, 4.016, 5.022];
b = [2.32, 4.123, 6.864, 8.535, 10.087];
times = [2, 4];
p = plot(a, b);
for i = 1:length(times)
p.DataTipTemplate.DataTipRows(1).Label = "Zeit in (s): ";
p.DataTipTemplate.DataTipRows(2).Label = "Wert: ";
datatip(p, times(i), b(times(i)));
end
I want the 'Zeit in (s)' values to be rounded in the plot. Currently the plot looks like this:
But it should be:
Zeit in (s): 2
Wert: 4.123
and
Zeit in (s): 4
Wert: 8.535
UPDATE:
Running this
...
for i = 1:length(times)
times(i)
p.DataTipTemplate.DataTipRows(1).Label = "Zeit in (s): ";
p.DataTipTemplate.DataTipRows(1).Value = round(a(times(i))).*ones(1, 5);
p.DataTipTemplate.DataTipRows(2).Label = "Wert: ";
datatip(p, a(times(i)), b(times(i)));
end
gives me:
Zeit in (s): 4
Wert: 4.123
and
Zeit in (s): 4
Wert: 8.535
So only the first 4 should be 2.
댓글 수: 0
채택된 답변
Adam Danz
2022년 9월 20일
편집: Adam Danz
2022년 9월 20일
If you want to round the x-value, set the format for the first DataTipTextRow of the DataTipTemplate object to '%.0f'. Apply it to the second DataTipTextRow for the y-value.
Demo:
x = rand(1,5)*50;
data = rand(size(x));
h = plot(x, data,'o');
% Set datatip template format for the x-variable
dtt = h.DataTipTemplate;
dtt.DataTipRows(1).Format = '%.0f';
% Create a datatip for demo purposes
disp(x(3))
datatip(h,x(3),data(3));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!