matlab - 可写逗号而不是点,用于小数点分隔符
问题描述
我将数据作为 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)
给出期望值。
解决方案
以下是如何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));
推荐阅读
- c# - 出现错误:协议消息包含无效标签(零),尽管字节完全相同
- cryptography - 任何人都知道如何搭建从 ERC20 代币到 BEP20 代币的桥梁
- python - 日期时间格式问题 Python
- python - 仅限 Spyder:asyncio - 无法关闭正在运行的事件循环
- php - 1062 键 'pim_catalog_completeness.PRIMARY' 的重复条目 '2147483647'
- c# - 如何使用 FileValidationAttribute 验证文档类型?
- javascript - 键盘没有在 iPhone 上自动打开
- linux - 在 Linux 中为 Delphi 应用程序使用 sctp_recvmsg() 和 epoll 实现 SCTP 功能时面临的问题
- regex - 在 curl 中禁用正则表达式解析
- ignite - 在 WAL 归档期间点燃 FileAlreadyExistsException