MATLAB的uint8数据类型变量保存 [英] MATLAB uint8 data type variable save

查看:2584
本文介绍了MATLAB的uint8数据类型变量保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何将uint8工作区变量保存到txt文件?
我试过使用MATLAB保存命令:

$ p $ 保存zipped.txt zipped -ascii


$ b

然而,命令窗口显示警告错误:


<警告:尝试将不支持的数据类型写入ASCII文件。

变量压缩不写入文件。



解决方案

为了编写它,只需在写入之前将您的值加倍。 / b>

  A = uint8([1 2 3])

toWrite = double(A)

save('test.txt','toWrite',' - ASCII')

uint8无法写入的原因隐藏在网上保存文档的格式部分,自己找了一下。

文档页面在这里: http://www.mathworks.com/help/matlab/ref/save.html



格式部分的表格之后的第三行(大约在页面的一半)说:

lockquote

每个变量必须是一个二维的双精度或字符数组


或者,dlmwrite可以编写uint8类型的矩阵,就像另外一个海报中提到的一样,我相信csv会工作但是我自己也没有测试过。



希望这会帮助你,但有点烦人!我认为uint8几乎专门用于MATLAB中的图像,但我假设将值写入图像在您的情况下是不可行的。

does anyone know how to save an uint8 workspace variable to a txt file? I tried using MATLAB save command:

save zipped.txt zipped -ascii

However, the command window displayed warning error:

Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'zipped' not written to file.

解决方案

In order to write it, simply cast your values to double before writing it.

A=uint8([1 2 3])

toWrite=double(A)

save('test.txt','toWrite','-ASCII')

The reason uint8 can't be written is hidden in the format section of the save doc online, took myself a bit to find it.

The doc page is here: http://www.mathworks.com/help/matlab/ref/save.html

The 3rd line after the table in the format section (about halfway down the page) says:

Each variable must be a two-dimensional double or character array.

Alternatively, dlmwrite can write matrices of type uint8, as the other poster also mentioned, and I am sure the csv one will work too, but I haven't tested it myself.

Hopefully that will help you out, kinda annoying though! I think uint8 is used almost exclusively for images in MATLAB, but I am assuming writing the values as an image is not feasible in your situation.

这篇关于MATLAB的uint8数据类型变量保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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