如何在shell脚本

时间:2017-07-17 06:24:17

标签: octave

final.txt的格式注意间距 format of final.txt

我正在尝试在gnu octave中创建一个饼图,但我希望它能够通过脚本文件运行

我尝试使用

octave -persist<< EOF
[a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18] = textread( 'final.txt', '%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ' ,'delimiter', ' ' ,1 );
pie([a1(2,1),a2(2,1),a3(2,1),a4(2,1),a5(2,1),a6(2,1),a7(2,1),a8(2,1),a9(2,1),a10(2,1),a11(2,1),a12(2,1),a13(2,1),a14(2,1),a15(2,1),a16(2,1),a17(2,1),a18(2,1)],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],{"200","201","202","203","204","301","302","303","304","400","401","402","403","404","500","501","502","503"});
title(a0(2,1));
legend("200","201","202","203","204","301","302","303","304","400","401","402","403","404","500","501","502","503");    
EOF

以上命令在我在octave命令行上直接使用时可以正常工作

但是当我尝试运行脚本文件时,我没有得到任何图表

final.txt内容

VMinstance  200 201 202 203 204 301 302 303 304 400 401 402 403 404 500 501 502 503
dadamfl3w6v 683 0   0   0   0   0   1   0   669 0   0   0   0   0   0   0   0   0
92ssadz9qpq 41  0   0   0   0   0   0   0   33  0   0   0   0   0   0   0   0   0
agcrarrcbqg 38  0   0   0   0   0   0   0   33  0   0   0   0   0   0   0   0   0
12t2bg6ws1j 25  0   0   0   0   0   0   0   17  0   0   0   0   0   0   0   0   0
gpusa121zdz 21  0   0   0   0   0   0   0   5520    0   0   0   0   0   0   0   0   0
dsad8urz24d 3   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
fggfbjrfkix 253 0   0   0   0   0   4   0   957 0   0   0   0   0   0   0   0   0
fqlie42dsxj 5   0   0   0   0   0   0   0   49  0   0   0   0   0   0   0   0   0
cbkajsbcj44 5   0   0   0   0   0   1   0   3   0   0   0   0   0   0   0   0   0
f4444fffffa 3968    0   0   0   0   0   4   0   3742    0   0   0   0   0   0   0   0   0

我在comandline上发送文字后的输出

a0 =
{
[1,1] = VMinstance
[2,1] = dadamfl3w6v
[3,1] = 92ssadz9qpq
[4,1] = agcrarrcbqg

1 个答案:

答案 0 :(得分:0)

当我使用你给出的final.txt文件运行你的代码时,readtxt输出的值中有很多NaN。例如,a1完全是NaN。通常在Matlab / Octave中,像你一样读取文件并不是一个好主意。我认为您应该删除final.txt文件的第一个columun中的文本,以获取

  200   201   202   203   204   301   302   303   304   400   401   402   403   404   500   501   502   503
  683     0     0     0     0     0     1     0   669     0     0     0     0     0     0     0     0     0

然后,您只需使用

将其加载到矩阵A
A=load("final.txt")

并使用适当的索引。

修改

以下是我从命令行运行代码时得到的结果:

>> [a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18]=textread( 'final.txt','%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ' ,'delimiter', ' ' ,1 );

>>a1 =

 200
 NaN
 NaN
 NaN

无论如何,即使它适合你,你所做的只是非常糟糕的做法。通过使用这种c风格的加载,你将失去抽象,更高级别的灵活性,并行化甚至matlab / octave提供的漂亮语法。

此外,如果您想知道某行对应的数据类型,只需在该行中添加一列,并使用您的数据类型指定并索引到某个字典。