Text output to the octave console

Suppose I have an A=5 variable, and I want to output it, but with some text added in front and after it. Something like this: "There are 5 horses." (remember that 5 must be mutable variable A )

If I write: disp("There are "),disp(A),disp(" horses.") , I get:

 There are 5 horses. 

BUT I want everything on one line.

How to do it?

+5
source share
2 answers

You can use:

 A = 5 printf("There are %d horses\n", A) 

output:

 There are 5 horses 

or even

 disp(["There are ", num2str(A), " horses"]) 

or even

 disp(strcat("There are ", num2str(A), " horses")) 

but you will need to add something because octave / matlab does not skip the space at the end of the line, so the output is:

 ans = There are5 horses 
+12
source

According to official documentation ,

Note that disp output always ends with a new line.

therefore, to avoid a new line, you should use an alternative to output data for each line or first combine one line and then disp it.

These are the listed options .

0
source

All Articles