1
votes

I am trying to print out a simple output table in scilab that is just a matrix of numbers with a top row of headers.The issue that arises is I don't know how to print strings in just the top row of an initialized matrix. For example,

 b= ['i', 'j'] 

prints

!i j! 

with exclamation points. What are these exclamation points for?

And

b = zeros(m1, m2)
b(1,:) = ['i', 'j' ...]

gives an error

!--error 10000 
%c_i_s: Affection of a string in a matrix of numbers is not implemented.

What is the meaning of this error? How do I otherwise print strings in a matrix but accessing one of the row/columns? I tried putting string(i) but this also did not work. Thank you

1

1 Answers

0
votes

A Scilab matrix has entries of numeric type. You can't put strings in it. Typically, one keeps header strings separately from data.

headers = ['i', 'j', 'k']
data = [1 2 3; 4 5 6; 7 8 9]

Instead of using disp, which formats data in a pre-determined way (in particular, it includes ! delimiters around arrays of strings), use mprintf to format it in your own way. A simple example:

mprintf('%s %s %s\n', headers)
mprintf('%d %d %d\n', data)

This outputs

i j k
1 2 3
4 5 6
7 8 9

Here is one with more spacing:

mprintf('%7s %7s %7s\n', headers)
mprintf('%7d %7d %7d\n', data)

Output:

  i       j       k
  1       2       3
  4       5       6
  7       8       9

See the docs on formatting parameters for more examples.