03Structured_Programming_&_Function 课后练习及思维导图
程序员文章站
2022-03-04 20:02:10
...
最近在跟着B站的——MATLAB教程系列-台大-郭彦甫——课程系统学习MATLAB的基本语法和功能。同时辅以CSDN这个平台来存储课后练习。初学MATLAB,代码存在诸多问题,欢迎指正。
课程链接:https://www.bilibili.com/video/av14503445/?p=3
练习一:
方法一:
%% Exercise 1
i = 1;
Sum=0;
while i < 1000
Sum = Sum + i;
i = i+1;
end
Sum
>> 499500.0000
方法二:这种并不符合题目的要求,仅用来确认结果正确!
%%
sum(1:999)
>> 499500.0000
练习二:
%% Exercise2
A = [0 -1 4;9 -14 25;-34 49 64];
a=1;
for i = 1:numel(A) %NUMEL Number of elements in an array or subscripted array expression.
% N = NUMEL(A) returns the number of elements, N, in array A, equivalent
% to PROD(SIZE(A))
if A(i) < 0
B(a) = i;
a = a+1;
A(i) = 0;
end
end
A
B
>>
A =
0 0 4
9 0 25
0 49 64B =
3 4 5
练习三:
%%
while (1)
prompt = 'Please input a temperature in degree Fahrenhait: ';
F = input(prompt);
if (~isempty(F))&&(isnumeric(F))
C = (F - 32).*(5/9);
% break
disp(['The converted temperature in degrees Celsius is ',num2str(C)]);
else
disp('error');
break
end
pause(1);
end
Please input a temperature in degree Fahrenhait: 54
The converted temperature in degrees Celsius is 12.2222
下面是我根据课程PPT和视频自行整理的思维导图,可用于快速复习回顾:
下一篇: Redis(九)--Redis集群