wis*_*shi 14 precision matlab plot datatip
我有精确损失的问题.我使用以下代码将CSV文件中的一组值导入MATLAB 7:
function importfile(fileToRead1)
%#IMPORTFILE(FILETOREAD1)
%# Imports data from the specified file
%# FILETOREAD1: file to read
DELIMITER = ',';
HEADERLINES = 0;
%# Import the file
rawData1 = importdata(fileToRead1, DELIMITER, HEADERLINES);
%# For some simple files (such as a CSV or JPEG files), IMPORTDATA might
%# return a simple array. If so, generate a structure so that the output
%# matches that from the Import Wizard.
[~,name] = fileparts(fileToRead1);
newData1.(genvarname(name)) = rawData1;
%# Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
Run Code Online (Sandbox Code Playgroud)
这个非常基本的脚本只需要指定的文件:
> 14,-0.15893555
> 15,-0.24221802
> 16,0.18478394
Run Code Online (Sandbox Code Playgroud)
并将第二列转换为:
14 -0,158935550000000
15 -0,242218020000000
16 0,184783940000000
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用数据光标选择一个点,它只显示3或4位精度:

有没有办法编程更高的精度来获得更精确的数据点?
gno*_*ice 30
您的数据不会丢失精度,数据光标显示只是没有显示完整的精度,因此文本框的大小更合理.但是,如果要在文本数据提示中提高显示精度,可以对其进行自定义.
如果右键单击"数据光标"文本框,则应该看到如下菜单:

如果您随后选择" 编辑文本更新功能..."选项,它将打开包含以下内容的默认m文件:
function output_txt = myfunction(obj, event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj, 'Position');
output_txt = {['X: ', num2str(pos(1), 4)], ...
['Y: ', num2str(pos(2), 4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ', num2str(pos(3), 4)];
end
Run Code Online (Sandbox Code Playgroud)
请注意,X和Y坐标数据的文本使用格式化num2str,第二个参数为a 4.这会将坐标值转换为具有4位精度的字符串表示形式.如果要显示更多数字,只需增加此数字,然后将新创建的m文件保存在路径中.
现在,您的数据提示文本应该为您的数字显示更高的精度.如果要以编程方式完成上述所有操作,首先要创建文本更新功能,将其保存到文件(如'updateFcn.m'),然后使用该功能打开Data Cursors datacursormode并将其设置为使用用户定义的文本更新功能.这是一个例子:
plot(1:10, rand(1, 10)); % Plot some sample data
dcmObj = datacursormode; % Turn on data cursors and return the
% data cursor mode object
set(dcmObj, 'UpdateFcn', @updateFcn); % Set the data cursor mode object update
% function so it uses updateFcn.m
Run Code Online (Sandbox Code Playgroud)
如果你想永久改变 - 警告:这是对MATLAB的轻微破解 - 打开:
C:\ Program Files\Matlab\R2007b\toolbox\matlab\graphics\@graphics\@datacursor\default_getDatatipText.m
或类似的文件,具体取决于您的版本和更改DEFAULT_DIGITS.