⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loops.m

📁 it s a 1st matlab script for testing
💻 M
字号:
%%% loops.m: to run this script, at the matlab prompt type%%% loops%%% clear;%clear the workspace% example 1%%% this is an example of for and if-then-else statements:%%% define an array filled with 8 random numbers, loop%%% through and if value < 0.5 then set to zero, otherwise%%% set to 1.0n = 8;A = rand(1,8) %%generate a vector A radomlyfor i = 1:n,	if A(i) < 0.5;	   A(i) = 0.0;	else	   A(i) = 1.0;	endendAfprintf('press enter to continue \n');pause%'example 2'%%% Divide a large number x by 2 until x<=1.%%% Keep track of the number of iterations and display it.x = 100000000000000;iter = 0;while (x > 1)  x = x / 2;  iter = iter + 1;endxsprintf('Number of iterations = %d', iter)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -