disp(X)函數只有一個輸入,當你有多個字符串作為輸入時就會報錯。
錯誤舉例:
disp('Alice is ' , num2str(12) , ' years old!' );
就會報錯--輸入參數過多。
但是將里邊的內容用中括號一括就成了一個字符串,
正確舉例:
str=['Alice is ' num2str(12) ' years old!'];
disp(str);
上邊這句話也就等價於:
disp=(['Alice is ' num2str(12) ' years old!']);
num2str可以將數字或變量轉換成字符串
if ~mod(i,100)%迭代輸出語句
%clc;
fprintf('%d generations completed\n',i);
end