matlab中disp函數的使用


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM