Guest User

Untitled

a guest
Jun 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. %% Change Octave prompt
  2. PS1('>> ');
  3. %% Change working directory in windows example:
  4. cd 'c:/path/to/desired/directory name'
  5. %% Note that it uses normal slashes and does not use escape characters for the empty spaces.
  6.  
  7. %% elementary operations
  8. 5+6
  9. 3-2
  10. 5*8
  11. 1/2
  12. 2^6
  13. 1 == 2 % false
  14. 1 ~= 2 % true. note, not "!="
  15. 1 && 0
  16. 1 || 0
  17. xor(1,0)
  18.  
  19.  
  20. %% variable assignment
  21. a = 3; % semicolon suppresses output
  22. b = 'hi';
  23. c = 3>=1;
  24.  
  25. % Displaying them:
  26. a = pi
  27. disp(a)
  28. disp(sprintf('2 decimals: %0.2f', a))
  29. disp(sprintf('6 decimals: %0.6f', a))
  30. format long
  31. a
  32. format short
  33. a
  34.  
  35.  
  36. %% vectors and matrices
  37. A = [1 2; 3 4; 5 6]
  38.  
  39. v = [1 2 3]
  40. v = [1; 2; 3]
  41. v = 1:0.1:2 % from 1 to 2, with stepsize of 0.1. Useful for plot axes
  42. v = 1:6 % from 1 to 6, assumes stepsize of 1 (row vector)
  43.  
  44. C = 2*ones(2,3) % same as C = [2 2 2; 2 2 2]
  45. w = ones(1,3) % 1x3 vector of ones
  46. w = zeros(1,3)
  47. w = rand(1,3) % drawn from a uniform distribution
  48. w = randn(1,3)% drawn from a normal distribution (mean=0, var=1)
  49. w = -6 + sqrt(10)*(randn(1,10000)); % (mean = -6, var = 10) - note: add the semicolon
  50. hist(w) % plot histogram using 10 bins (default)
  51. hist(w,50) % plot histogram using 50 bins
  52. % note: if hist() crashes, try "graphics_toolkit('gnu_plot')"
  53.  
  54. I = eye(4) % 4x4 identity matrix
  55.  
  56. % help function
  57. help eye
  58. help rand
  59. help help
Add Comment
Please, Sign In to add comment