18-matlab知识点复习一

时间:2021-02-19 03:58:29
clc;
clear; %% 输出
clc, clear;
fprintf('%.19f', pi);
fprintf('%d', 110);
inf
pi
disp([1,3,5])
disp('a');
disp(num2str(12)); %numstr()是将其他类型的变量转化成字符串的形式
disp(str2num('234'));
a = str2num('1')
b = a + 1 %% 输入:
clc, clear;
a=input('please input a number:')
b=input('请输入一个字符串:','s')
c=input('请输入一个矩阵:') % 输入要带中括号:[1,2] %% 矩阵生成函数:
clc, clear;
A = zeros(3,4)
B = ones(3,4)
C = eye(3,3) % 对角矩阵 %% 数组字符串切割
clc, clear;
s=['aa', ',', '23', ',44']
a = s(2:3)
s2 = '1232323aaaa'
b = s2(5:9) %% 循环:
clc;
clear;
a=[2 5 6 9888 8 86 4 5 6 65 3 54];
len = size(a,2);
max_n = -1;
for i = 1:len
if a(i) > max_n
max_n = a(i);
end
end
fprintf('for最大的数: %d\n', max_n);
max_n = -1;
i = 1;
while i <= len
if a(i) > max_n
max_n = a(i);
end
i = i + 1;
end
fprintf('while最大的数: %d\n', max_n); %% 调用函数:
clc;
clear;
[s,l] = circle(2) %调用 -----------------------
function [s,l] = circle(r)
s = pi * (r ^ 2);
l = 2 * pi * r;
end