Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab:使用';可写';将工作区变量保存到.txt_Matlab_Export_Long Integer_Short - Fatal编程技术网

Matlab:使用';可写';将工作区变量保存到.txt

Matlab:使用';可写';将工作区变量保存到.txt,matlab,export,long-integer,short,Matlab,Export,Long Integer,Short,希望使用友好的writetable命令而不是fprintf保存一个大表。不幸的是,表格值是double精度和long格式,这导致.txt文件无法读取长数字。使用 format Style 命令您可以在命令窗口中设置显示。Matlab帮助中提到: format函数只影响数字在命令窗口中的显示方式,而不影响MATLAB®计算或保存数字的方式。 除了返回到稍微笨拙的fprintf命令外,是否有一种方法可以将我的表值设置为short或shortg格式,以便使用writetable导出到.txt?fp

希望使用友好的
writetable
命令而不是
fprintf
保存一个大表。不幸的是,表格值是
double
精度和
long
格式,这导致.txt文件无法读取长数字。使用

format Style 
命令您可以在命令窗口中设置显示。Matlab帮助中提到:

format函数只影响数字在命令窗口中的显示方式,而不影响MATLAB®计算或保存数字的方式。


除了返回到稍微笨拙的
fprintf
命令外,是否有一种方法可以将我的表值设置为
short
shortg
格式,以便使用
writetable
导出到.txt?

fprintf
非常有效,您只需定义数字的格式即可

fid=fopen('mydatafile.txt','w'); % open a txt and set the property to write
data=rand(100,3); 
fprintf(fid,'%3.3f; %3.3f; %3.3f\n',data(:,:)); % print with 3 values, 3 of them after the comma, separated by ';'
fclose(fid) % close your txt

可能是您的记事本在一行中显示这些值。为此,您最好使用

可写输出使用长g格式的数字变量,以及在文本文件中使用分类或字符变量作为不带引号的字符串。
您没有选择余地。抱歉,伙计-接受您的答案太早了。没有注意到示例中的数组是数字的。我正在使用
,而fprintf不适用于该数组类型。Matlab抛出:>未为“表”输入定义使用fprintf>函数的错误。