我对精度损失有意见我使用以下代码将一组值从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

这个非常基本的脚本只接受指定的文件:
> 14,-0.15893555
> 15,-0.24221802
> 16,0.18478394

并将第二列转换为:
14  -0,158935550000000
15  -0,242218020000000
16  0,184783940000000

但是,如果我用数据光标选择一个点,它只显示3或4位精度:
有没有一种方法可以编程更高的精度来获得更精确的数据点?

最佳答案

您的数据没有丢失精度,数据光标显示没有显示完整精度,因此文本框的大小更合理但是,如果要提高文本数据提示中显示的精度,you can customize it
如果在数据光标文本框上单击鼠标右键,您将看到如下菜单:
如果选择编辑文本更新功能选项,它将打开包含以下内容的默认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

注意,X和Y坐标数据的文本是使用num2str格式化的,第二个参数是a4这将坐标值转换为具有4位精度的字符串表示形式如果您想要显示更多的数字,只需增加这个数字,然后将新创建的m文件保存在path上。
现在,数据提示文本应该更精确地显示数字如果您想以编程方式完成以上所有操作,首先要创建文本更新函数,将其保存到一个文件(如'updateFcn.m'),然后使用函数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

10-06 13:32
查看更多