Table 替换不同类型数据时字段数字发生变化
Table fields digit change when replacing data of different types
基于此post(),我运行脚本上了table。在脚本中,我提取了一列,运行 上的函数,并用相同但复制的 table(原始)的新列替换旧列。奇怪的是,我发现修改后的列数据没有正确存储在新的 table 中。为什么?我怀疑这是因为 分类 。我该如何解决?
代码:
clc;
clear all;
dataInput = webread('https://people.sc.fsu.edu/~jburkardt/data/csv/hw_25000.csv');
tempCol = (f(table2array(dataInput(:,2))));
newDataInput = dataInput;
newDataInput(:,2) = table(tempCol);
function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting.
%at each tab. categorical is needed to remove ' 's that appear around char
%in the output PDF file with newer MATLAB versions
%e.g. with R2018a, there are no ' ' in the output file but ' ' appears with R2020a
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (<undefined>) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end
您不能将一种类型的值替换为另一种类型的值。相反,只需重写该列。即使用:
newDataInput.(newDataInput.Properties.VariableNames{2}) = tempCol;
而不是:
newDataInput(:,2) = table(tempCol);
基于此post(
代码:
clc;
clear all;
dataInput = webread('https://people.sc.fsu.edu/~jburkardt/data/csv/hw_25000.csv');
tempCol = (f(table2array(dataInput(:,2))));
newDataInput = dataInput;
newDataInput(:,2) = table(tempCol);
function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting.
%at each tab. categorical is needed to remove ' 's that appear around char
%in the output PDF file with newer MATLAB versions
%e.g. with R2018a, there are no ' ' in the output file but ' ' appears with R2020a
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (<undefined>) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end
您不能将一种类型的值替换为另一种类型的值。相反,只需重写该列。即使用:
newDataInput.(newDataInput.Properties.VariableNames{2}) = tempCol;
而不是:
newDataInput(:,2) = table(tempCol);