我将数据作为 Matlab 数字存储在“.mat”文件中,我想将此表打印为 tsv 文件,但是我想将小数点替换为小数点逗号。
这是我试过的。
measurements=load('Emeasured.mat');
writetable(struct2table(measurements),"messwertelab1.tsv",'Delimiter','\t')
有效,但数字“丑陋”,我会使用像 num2eng
这样的工具,但我需要对其进行本地化,以便小数点分隔符为逗号。
nf=java.text.NumberFormat.getInstance(java.util.Locale.GERMAN);
nformat=@(num)(nf.format(num))
arrayfun(nformat,measurements.column)
好像出错了,报错信息是。
<块引用>无法在索引 1 处分配到统一输出数组 2。将“UniformOutput”设置为 false。
原因:
索引超过 Java 数组维度
为什么我不能遍历数组?
nformat(2.124)
给出了预期值。
答案 0 :(得分:0)
以下是如何使用逗号代替小数点分隔符将 writetable
输出到带有数字的表格中。
df=java.text.DecimalFormat("0", ...
java.text.DecimalFormatSymbols.getInstance(java.util.Locale.GERMAN));
%or the locale you desire.
df.setMaximumFractionDigits(340);
%340 is the maximum Value.
%When calling the function arrayfun with `UniformOutput` to false
%you get a collection of cells back, this is how to flatten them to a list of strings
vflatten = @(x, varargin) vertcat(x{:});
%This is the callback for arrayfun
nformat=@(num)(string(df.format(num)));
%Finally your formatted arrays.
vflatten(arrayfun(nformat,yourArrayWithNumbers,"UniformOutput",false));