From bug-octave-request at bevo dot che dot wisc dot edu Thu Nov 5 07:49:19 1998 Subject: Problems with arrays of strings From: "John W. Eaton" To: Francesco Potorti` Cc: Octave bugs list Date: Thu, 5 Nov 1998 07:47:53 -0600 (CST) On 5-Nov-1998, Francesco Potorti` wrote: | I read in the octave manual: | | - Function File: str2mat (S_1, ..., S_N) | Return a matrix containing the strings S_1, ..., S_N as its rows. | Each string is padded with blanks in order to form a valid matrix. | | *Note:* This function is modelled after MATLAB. In Octave, you | can create a matrix of strings by `[S_1; ...; S_N]' even if the | strings are not all the same length. | | but: | | octave:2> x=["a";"ab"] | x = | | a | ab | | octave:4> y=x(1,:) | y = a | octave:5> length(y) | ans = 2 <-- strings are all the same length, contrary to what I expected | octave:7> strcat("`",y,"'") | ans = `a ' | octave:8> version | ans = 2.0.13.91 Perhaps the docs should be clearer. Both str2mat ("a", "ab") and ["a"; "ab"] are equivalent in Octave. They both pad with blanks. You can use the deblank function to strip them off. I know it's inconvenient, but I don't know how to fix this for arrays of strings/character matrices and still be compatible with Matlab. | Moreover, running this script I get: | | ---------- test.sh ------- | #! /usr/bin/octave -qf | [argv(1,:), ".inp"] | -------------------------- | $ test.sh td6 25407 1025724 | ans = td6 The problem here is that because of an oversight on my part, Octave pads the argv vector with 0 instead of blanks. I'm not sure whether that is worth fixing for the 2.0.x series. In Octave 2.1.x (x > 8) argv is implemented as a list of strings, so this problem is avoided. | and I also get an internal error from octave running the script appended: | | $ make_markov_inp.sh td6 25407 1025724 | ofile = td6 | error: octave_char_matrix_str::valid_as_scalar_index(): not implemented | error: string type invalid as index value | error: evaluating index expression near line 108, column 16 | error: evaluating assignment expression near line 108, column 14 | error: called from `make_markov_inp' in file `/home/foda/fracas/make_markov_inp.m' I think the problem is that you have used the name `stat' as a variable and then you are trying to call it as a function. Once you've used the name as a variable, Octave thinks you are trying to index the variable instead of call the function | stat = find (abs(diag(l)-1) < sqrt(eps)); # Locate eigenvalues equal to 1 | ... | ofile = [ifile, ".inp"] | [s, err] = stat (ofile) jwe