[問題] 想請問一下關於echo指令的用法已回收
最近在自學MATLAB
上網捉了一些教學PPT 讀到關於echo指令
有查了一下help
但他寫的非常簡短 而實際例子我也試不出個所以然
所以想請教一下echo的用法是...
範例:
echo off
clear all
home;
echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Programming in Matlab %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%% Scripts
%
% - Simple sequence of commands.
% - Variables located in global workspace
% - No memory allocation or prior declaration of variables
%
home
%
%% Functions
%
% - Like a function or procedure you would write in any other language
% - Can return multiple arguments, accepts variable numbers of inputs
% - Just like a script except first line should be:
%
% function [out1, out2, ..., outN] = MyFunction(in1, in2, ..., inN)
%
% - Variables only have local scope of course
% - Can make variables global using 'global'
% - Can make variables persistent (=static) using 'persistent'
% - You cannot put a function inside a script file
%
home
%
%% Inline functions
%
% function_name = inline('function description', 'var1', 'var2', ...)
%
% Example:
%
my_func = inline('(x+y)*pi/3 - x^2', 'x', 'y');
my_func(3,4) % x=3, y=4
home
% %
% % In a script file or function, you can use 'keyboard' to
% % help debug. Typing 'return' at the 'K>>' prompt returns
% % to the script or function.
% %
% keyboard;
%
%% Some programming guides:
%
% - IF, ELSEIF (one word!!), ELSE, END ladders:
%
% x = rand(1);
% y = rand(1);
%
% disp([x y])
%
% IF(my_func(x, y) > pi)
% disp('GREATER THAN PI')
% ELSEIF(x < y)
% disp('X LESS THAN Y')
% ELSE
% disp('NONE OF THE ABOVE')
% END
%
echo off
x = rand(1);
y = rand(1);
disp([x y])
if(my_func(x, y) > pi)
disp('GREATER THAN PI')
elseif(x < y)
disp('X LESS THAN Y')
else
disp('NONE OF THE ABOVE')
end
echo on
%
% - NOT is represented by '~' instead of '!'
%
% if( x ~= y)
% disp('X NOT EQUAL TO Y')
% end
%
echo off
if( x ~= y)
disp('X NOT EQUAL TO Y')
end
echo on
%
% - AND and OR use && and ||
%
% if( x < y && x < .5)
% disp('TRUE')
% end
%
echo off
if( x < y && x < .5)
disp('TRUE')
end
echo on
home
%
% - FOR and WHILE as you would expect
% - Note that your use of FOR and WHILE loops should be
% _very_ minimal. Matlab is MUCH faster at vectorized
% operations. Almost any operation can be vectorized with
% a little (or a lot of) thought!!
% - Nested FOR loops are usually a very bad idea!
%
% for i=1:10
% disp(i)
% end
%
echo off
for i=1:10
disp(i)
end
echo on
echo off
p.s: 順便想請問一下
home的用法跟clc會有點雷同嗎
有點不太懂~_~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.73.36
→
04/02 10:29, , 1F
04/02 10:29, 1F
→
04/02 10:31, , 2F
04/02 10:31, 2F