Octave basic operation

Basic Command

~= %not equal
&& %and
|| %or

a=3 %semicolon supressing output
b=‘hi’
disp(a) %display value a
disp(sprint(‘2 decimals: %0.2f’,a)) %display 2 digits

A = [1 2; 3 4; 5 6] % generate a matrix
v = 1:0.1:2
v = 1:6
ones(2,3)
C = 2ones(2,3) % generate 23 1 matrix

w = rand(1,3) %randomly generate 1*3 matrix

I = eye(6) %6 *6 I matrix
size(A) % size of matrix
length(A) % length of a vector

load xxxx.file % load the data
load(‘xxxxx’)
who whos %shows all the variables
clear % delete a variable
v = a(1:10) % show first 10 of a
save file.txt v % save as v
A(3,2) % the 3rd row and 2nd column of A
A(2,:) % second row of A
A([1,3]😅
A(:,2) = [10;11;12] % attribute value
A = [A, [100,101,102]] % append the matrix to the right
A(😃 % put all elements of A into a single vector
C = [A B] or C = [A,B] % connect A and B side by side
C = [A;B] % connect A and B bottom and up

Caculation

A .^ 2 %all the elements square inA
1 ./ A % reciprocal of A
log(v)
V + ones(length(v),1) %add all in V by one
A’ % transpose
[val,ind] = max(a) % return max and position
A < 3 $ boolen judgement
find(a ❤️) % return position
pro, sum, ceil, floor
max(A,[],2] % 1 COLUMN MAXIUM 2 ROW MAXIUM
pinv(A) % find invert of A

Plot

t = [0:0.1:0.98]
y2 = sin(t)
plot(t,y2,‘r’) % color
hold on; %hold the layer
legend, xlabel, ylabel
subplot
imagesc(A) %show the matrix
imagesc(A),colorbar,colormap gray;

Control Statement

for i = 1:10,
v(i) = 2 ^ i;
end;

while i <= 5,
v(i) = 100;
i = i + 1;
end;

while true,
v(i) = 999;
i = i + 1;
if i == 6,
break;
end;
end;

if v(1) ==1,
disp(‘The value is one’);
elseif v(1) ==2,
disp(‘The value is two’);
end;

Function File Name with .m in the file name
Write the function in the file

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值