我想将whos
命令的结果导出到Scilab中的tlist
:
Name Type Size Bytes
%_k constant 1x1 0
%_LG_all string 141x1 0
%_lhs constant 1x1 0
%_nams string 133x1 0
%_nams_all string 141x1 0
%_nams_global string 8x1 0
%_rhs constant 1x1 0
%_sz string 1x1 0
%_typ constant 1x1 0
在Unix术语中,它被称为使用pipe
运算符完成的|
ing。但我不知道如何在Scilab中做到这一点。如果你能帮助我,我将不胜感激。
您可以编辑whos
本身的源代码(它是用Scilab语言编写的):
--> edit whos
通过向此函数添加输出
function out=whos(%_opt,%_sel)
以及第118行的以下说明
out(%_k) = struct("name",%_nams_all(%_k),"type",%_typn,...
"dimensions",%_sz,"bytes",%_vol_all(%_k)*8);
你会得到你想要的。当然,你也可以创建一个tlist ...
S.
我找到了一个非常丑陋的解决方法。有一个diary
函数,它将最后几个sdout
条目导出到一个文件中。通过使用正则表达式和一些文件魔法,我可以将whos
输出作为矩阵:
WhosExp = "/([\%\_\#\!\$\?a-zA-Z]+[\%\_\#\!\$\?a-zA-Z0-9]*)\s+(constant|polynomial|function|handle|string|boolean|list|rational|state\-space|sparse|boolean sparse|hypermat|st|ce|fptr|pointer|size implicit|library|int8|uint8|int16|uint16|int32|uint32|\_EObj|\_EVoid)\*?\s+((\d+)x(\d+)|\?)?\s+(\d+)/"
TempFile = TMPDIR + '/TempDiary.txt';
clc;
diary(TempFile)
whos;
diary(0)
clc;
TempID = mopen(TempFile, 'rt');
TempInfo = fileinfo(TempFile)
TempString = mgetstr(TempInfo(1), TempID);
mclose(TempID);
mdelete(TempFile);
[start, final, match, foundString] = regexp(TempString, WhosExp);
foundString
是矩阵/列表,如果需要可以变成tlis
。
附: Scilab社区真是太遗憾了。每次我问一个问题,我都会自己回答。