Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing strings from a array of strings in GNU Octave

Tags:

string

octave

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
like image 907
Archisman Panigrahi Avatar asked Dec 18 '22 13:12

Archisman Panigrahi


1 Answers

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

like image 142
Tasos Papastylianou Avatar answered Jan 17 '23 11:01

Tasos Papastylianou