在Matlab中的两个数字之间插入+-(即\ pm) [英] inserting +- (i.e. \pm) between two numbers in matlab

查看:1214
本文介绍了在Matlab中的两个数字之间插入+-(即\ pm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Matlab中创建的表中的x和y之间插入符号+-(\ pm)

I want to insert the symbol +- (\pm) between x and y in table created in matlab

x = (1:1:5)';
y = x*5/100;
table = [x y]

因此,输出为

1.0000 +/- 0.0500
2.0000 +/- 0.1000
3.0000 +/- 0.1500
4.0000 +/- 0.2000
5.0000 +/- 0.2500

如果我们也可以将正负写在正负下方.

If we can also write the minus exactly below plus.

推荐答案

您可以在MATLAB中使用Unicode字符.以下作品:

You can use unicode characters in MATLAB. The following works:

>> fprintf('%f ± %f\n', table.')
1.000000 ± 0.050000
2.000000 ± 0.100000
3.000000 ± 0.150000
4.000000 ± 0.200000
5.000000 ± 0.250000

请注意,fprintf按存储顺序在输入矩阵的所有元素之间循环(从第一列开始向下).因此,有必要转置数据数组(table.')以便在一个命令中将其打印出来.

Note that fprintf cycles through all the elements of the input matrix in storage order (down the first column first). So it was necessary to transpose the data array (table.') to print it in one command.

这也适用于在MacOS上打印到文件:

This works for printing to file as well on MacOS:

f = fopen('mytextfile.txt','wt');
fprintf(f,'%f ± %f\n', table.');
fclose(f);

这篇关于在Matlab中的两个数字之间插入+-(即\ pm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆