Iteration conditioned (While. .. end).
This syntax is used to perform the process without a known repetition of repetition. Iterations of this type of repetition only stop when it reaches certain conditions. Eg calculate the amount of glass needed to accommodate the contents of the tub. The way the writing is as
follows:
while conditions
commands
end
1. In the command window, type:For clarity, the following are examples of its use in the program:
>> Edit
2. Press Enter, then when MATLAB editor appear, type or copy the program below:
clear all;
clc;
disp ('--------------------------');
disp ( 'My 5th Training Program');
disp ('--------------------------');
vbasin = input ( 'volume of the tub (ltr) =');
vglass = input ( 'glass volume (ltr) =');
nglass = 0;while vbasin> 0nglass = nglass +1;
vbasin = vbasin - vglass;
end;
disp ([ 'glasses required =' num2str (nglass)]);
3. When finished typing the above programs, you save in the directory c: / mytraining, with the name training05.m
4. Ensure your file storage directory is contained in the directory search list MATLAB. Learn it in the MATLAB directory management here. Then type the file name without the extension training04:
>> training05
5. Press Enter, then the program will run and produce as follows:
--------------------------
My 5th Training Program
--------------------------
bath volume (ltr) = 2
glass volume (ltr) = 0.2
glass required = 11
6. Done
0 comments:
Post a Comment