2

When I run below octave code the command window displays :

>> first
x =

    10
    20
    30
    40
    50
    60
    70
    80
    90
   100

y =

   14
   17
   18
   14
   15
   14
   13
   12
   11
    4

m =  10
x =

     1    10
     1    20
     1    30
     1    40
     1    50
     1    60
     1    70
     1    80
     1    90
     1   100

-- less -- (f)orward, (b)ack, (q)uit

I'm required to continually press (f) to complete program and view plot : plot(x(:,2), x*theta, '-');

Octave code :

x = [10
    20
    30
    40
    50
    60
    70
    80
    90
    100]
y = [14
    17
    18
    14
    15
    14
    13
    12
    11
    4]

m = length(y)

x = [ones(m , 1) , x]

theta = zeros(2, 1);        

iterations = 10;
alpha = 0.000007;

for iter = 1:iterations
     theta = theta - ((1/m) * ((x * theta) - y)' * x)' * alpha;
     #theta
end

#plot(x, y, 'o');
#ylabel('Response Time')
#xlabel('Time since 0')
plot(x(:,2), x*theta, '-');

How to prevent user interaction with command window so that program runs to completion and displays prompt and not requiring user interaction ?

blue-sky
  • 51,962
  • 152
  • 427
  • 752

1 Answers1

3

To prevent your variables from printing altogether, simply add a semicolon to the end of each variable assignment:

m = length(y)   %// **will** print to the console
m = length(y);  %// will *not* print to the console

To print your variables to the console, but avoid Octave pausing the output when it gets to the bottom of the screen, add more off to the beginning of your script to turn off paging.

https://www.gnu.org/software/octave/doc/interpreter/Paging-Screen-Output.html

Type more on to switch it back on.

beaker
  • 16,331
  • 3
  • 32
  • 49
  • thanks, so by default octave will print all created variables to screen? – blue-sky Aug 29 '15 at 14:28
  • @blue-sky Sorry, I misinterpreted your question. I'll modify my answer. – beaker Aug 29 '15 at 14:29
  • @blue-sky no. Only when you forget to end your statements with `;` – carandraug Aug 29 '15 at 14:29
  • @blue-sky While we're giving tips about semicolons, you don't have to use that multi-line format to declare column vectors. You can place semicolons between the elements and place them all on the same line: `x = [10; 20; 30; 40; 50; 60; 70; 80; 90; 100];` – beaker Aug 29 '15 at 14:39