How to access the whole elements hello and ahoy in Octave? Only the first character in each string is being printed.
octave:1> s = ["hello";"ahoy"]
s =
hello
ahoy
octave:2> s(1)
ans = h
octave:3> s(2)
ans = a
How to access the whole elements hello and ahoy in Octave? Only the first character in each string is being printed.
octave:1> s = ["hello";"ahoy"]
s =
hello
ahoy
octave:2> s(1)
ans = h
octave:3> s(2)
ans = a
Use cell arrays instead.
octave:1> s = { 'hello'; 'ahoy' };
octave:2> s{1}
ans = hello
octave:3> s{2}
ans = ahoy
See https://octave.org/doc/v5.2.0/Cell-Arrays.html#Cell-Arrays
Check the size and type of s to understand what's going on:
octave:5> size(s)
ans =
2 5
octave:6> class(s)
ans = char
It's a 2x5 matrix of characters. To index, use matrix indexing. For example getting the first row:
octave:7> s(1,:)
ans = hello