2019-02-12 Octave基本命令

2019-02-12  本文已影响0人  孟媛的笔记
octave:1> 5+6
ans =  11
octave:2> 3-2
ans =  1
octave:3> 5*8
ans =  40
octave:4> 1/2
ans =  0.50000
octave:5> 2^6
ans =  64
octave:6>
octave:6>
octave:6> 1==2
ans = 0
octave:7> 1==1
ans = 1
octave:8> 1~=2
ans = 1
octave:9> 1&&0   %AND
ans = 0
octave:10> 1||0  %OR
ans = 1
octave:11> xor(1110,111)
ans = 0
octave:12> xor(1,0)
ans = 1
octave:13> PS1('>> ');
>>

 

>> a=3
a =  3
>> a=3;   % semicolon suppressing output
>> a
a =  3
>> b='hi'
b = hi
>> c=(3>=1)
c = 1
>>
>>
>> a=pi;
>> a
a =  3.1416
>> disp(sprintf('2 decimals: %0.2f', a))
2 decimals: 3.14
>> disp(sprintf('2 decimals: %0.6f', a))
2 decimals: 3.141593
>> disp(sprintf('6 decimals: %0.6f', a))
6 decimals: 3.141593
>> a
a =  3.1416
>> format long
>> a
a =  3.141592653589793
>> format short
>> a
a =  3.1416
>>

 

>> A = [1 2; 3 4; 5 6]
A =

   1   2
   3   4
   5   6

>> A = [1 2;
> 3 4;
> 5 6]
A =

   1   2
   3   4
   5   6

>> V = [1 2 3]
V =

   1   2   3

>> V = [1; 2; 3]
V =

   1
   2
   3

>> V = 1:0.2:2    %row vector: start from 1, increment steps of 0.2, until get up to 2
V =

    1.0000    1.2000    1.4000    1.6000    1.8000    2.0000

>> V = 1:6
V =

   1   2   3   4   5   6

 

>> I = eye(4)
I =
Diagonal Matrix

   1   0   0   0
   0   1   0   0
   0   0   1   0
   0   0   0   1

>> ones(2,3)
ans =

   1   1   1
   1   1   1

>> C = 2*ones(2,3)
C =

   2   2   2
   2   2   2

>> z = zeros(1,3)
z =

   0   0   0

>> w = rand(1,3)
w =

   0.71770   0.32685   0.58547

>> w = rand(3,3)    %random between 0 and 1 
w =

   0.74000   0.90124   0.84418
   0.60895   0.41059   0.70267
   0.32198   0.79994   0.13292

>> w = randn(1,3)    %randn:高斯分布/正态分布, 均值:0,方差/标准差:1
w =

  -0.012404   0.076510   0.887509

>> w = -6 + sqrt(10) * (randn(1,10000));   %10000个数,服从正态分布,均值为-6,方差为10
>> hist(w,50)    %画一个有50根条的柱状图

 

help命令:

>> help rand
上一篇下一篇

猜你喜欢

热点阅读