简体   繁体   English

八度。 一种显示数字数组和char数组彼此相邻的方法?

[英]Octave. A way to display numeric arrays and char arrays next to each other?

I want to display matrices Yn (5x5), Un(5x1), Jn(5x1) in a format: Yn * Un = Jn, like this: 我想以以下格式显示矩阵Yn(5x5),Un(5x1),Jn(5x1):Yn * Un = Jn,如下所示:

multiply_sign = [ nan; nan; '*'; nan; nan ];
equals_sign = [ nan; nan; '='; nan; nan ];
YnUnJn = [Yn, multiply_sign, Un, equals_sign, Jn]

I get an error, that the '*' and '=' vectors are char-arrays and Yn,Un,Jn are numeric-arrays. 我得到一个错误,即'*'和'='向量是char数组,而Yn,Un,Jn是数字数组。 Is there perhaps a way to get round it? 也许有办法绕过它吗?

In matlab it's possible to use uitable, but it's not implemented in Octave. 在matlab中,可以使用uitable,但不能在Octave中实现。

Input are Yn, Un, Jn matrix'es with dimention as specified above. 输入是具有上述尺寸的Yn,Un,Jn矩阵。

Output is YnUnJn matrix or whatever that looks like specified format: matrix Yn, then the "*" sign, then Un, then "=" sign, then Jn matrix. 输出是YnUnJn矩阵或任何看起来像指定格式的矩阵:矩阵Yn,然后是“ *”号,然后是Un,然后是“ =”号,然后是Jn矩阵。

Like this: 像这样: https://imgur.com/wUEKbyU

Here is a basic implementation in Octave. 这是Octave的基本实现。 Note that disp function in octave returns a string. 请注意,八度中的disp函数返回一个字符串。

Yn = rand(5)-.5;
Un = rand(5,1)-.5;
Jn = rand(5,1)-.5;
b = blanks(size(Yn ,1));

dsp=@(x)char(strsplit(disp(x),'\n'));

multiply_sign = strjust(['*' b],'center').';
equals_sign   = strjust(['=' b],'center').';

disp([dsp(Yn) multiply_sign dsp(Un) equals_sign dsp(Jn)])


   0.1610588   0.1244556  -0.2046512  -0.1799725  -0.3302048    0.364565    0.167053
  -0.1774412   0.3618586   0.4974047   0.4349322  -0.4689669   -0.013163   -0.442009
   0.1016794  -0.0991844   0.4728800   0.2046589  -0.2876299*   0.091990=   0.405725
  -0.2048010  -0.4256928  -0.0517186   0.2915129  -0.3435698   -0.376725    0.342397
  -0.2740378  -0.0907411   0.0090493   0.4677547  -0.2294902   -0.136846    0.096984

.

In MATLAB you may need to use evalc('disp(Yn)') . 在MATLAB中,您可能需要使用evalc('disp(Yn)')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM