标签: chararray

MATLAB 是否提供从双精度型到字符串型的无损转换函数?

太长了;博士

我只是在寻找两个函数,ffrom doubletostringgfrom stringto double,这样g(f(d)) == d对于任何双精度d(标量和实数double)。

原问题

如何以可逆的方式将 a 转换double为 astring或数组?char我的意思是,之后我可以将该string/char数组转换回以double检索原始结果。

我发现formattedDisplayText,在某些情况下它有效:

>> x = eps

x =

     2.220446049250313e-16

>> double(formattedDisplayText(x, 'NumericFormat', 'long')) - x

ans =

     0
Run Code Online (Sandbox Code Playgroud)

但在其他情况下则不然

x = rand(1)

x =

   0.546881519204984

>> double(formattedDisplayText(x, 'NumericFormat', 'long')) - x

ans =

     1.110223024625157e-16
Run Code Online (Sandbox Code Playgroud)

至于这个和其他工具,例如num2str,,mat2str最后它们都要求我决定精度,而我想表达“使用您需要的任何精度(MATLAB)以便能够读回您自己的数字” ”。

string precision matlab type-conversion chararray

5
推荐指数
1
解决办法
236
查看次数

为什么2个地址之间的差异不是元素大小的倍数

我不明白为什么 var 是 6,它是如何计算的

#include <iostream>
using namespace std;
  
int main()
{
    char *A[] = { "abyx", "dbta", "cccc"};
    int var = *(A+1) - *A+1;
    cout << "1: " << (*(A+1)) << "\n";
    cout << "2: " << (*A+1) << "\n";
    cout << "char: " << var << "\n";
    cout << &A[0][1] - &A[1][0] << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers pointer-arithmetic chararray

2
推荐指数
1
解决办法
117
查看次数