【MATLAB】基本绘图 ( text 函数 | annotation 函数 | 绘制图像示例 )
生活随笔
收集整理的這篇文章主要介紹了
【MATLAB】基本绘图 ( text 函数 | annotation 函数 | 绘制图像示例 )
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 一、text 函數
- 二、annotation 函數
- 三、繪制圖像示例
一、text 函數
參考文檔 : https://ww2.mathworks.cn/help/matlab/ref/text.html
使用 text 函數 , 可以在坐標系的指定位置繪制文字 ;
在 坐標系的 (0.5,0.5)(0.5,0.5)(0.5,0.5) 點位置 , 繪制積分符號文字 , 該文字是 latext 數學公式 ;
代碼示例 :
% latext 數學公式 , 積分 str = '$$\int_{0}^{2} x^2\sin(x)dx$$';% 在 0.5 0.5 位置繪制字符串 % 'Interpreter', 'latex' 表示字符串的格式是 Latex 數學公式 % 后兩個參數是固定寫法 text(0.5, 0.5, str, 'Interpreter', 'latex');這里涉及到 latext 語法 :
$$\int_{0}^{2} x^2\sin(x)dx$$該 latext 數學公式展示效果如下 :
∫02x2sin?(x)dx\int_{0}^{2} x^2\sin(x)dx∫02?x2sin(x)dx
運行結果 :
二、annotation 函數
參考文檔 : https://ww2.mathworks.cn/help/matlab/ref/annotation.html
使用 annotation 函數繪制箭頭 :
% latext 數學公式 , 積分 str = '$$\int_{0}^{2} x^2\sin(x)dx$$';% 在 0.5 0.5 位置繪制字符串 % 'Interpreter', 'latex' 表示字符串的格式是 Latex 數學公式 % 后兩個參數是固定寫法 text(0.5, 0.5, str, 'Interpreter', 'latex');% 繪制一個箭頭 , % 'X', [0.2, 0.5], 表示 x 軸方向 , 從 0.2 到 0.5 % 'Y', [0.2, 0.5], 表示 y 軸方向 ,, 從 0.2 到 0.5 annotation('arrow', 'X', [0.2, 0.5], 'Y', [0.2, 0.5] );運行效果 :
三、繪制圖像示例
繪制兩個圖像 :
- f=t2f = t^2f=t2
- g=sin(2πt)g = sin(2 \pi t)g=sin(2πt)
繪圖范圍是 [1,2][1,2][1,2] 之間 ;
代碼 :
% x 軸變量 t = 0 : 0.05 : 2; % 函數1 平方函數 f = power(t, 2); % 函數2 正弦函數 g = sin(2 * pi * t);% 繪制多個圖像 hold on % 繪制平方函數 % 實線 + 紅色 + 圓 plot(t, f, 'or-'); % 繪制正弦函數 % 虛線 + 綠色 + 三角 plot(t, g, '^g--');% 第一個曲線設置 f=t^2 % 第二個曲線設置 g=sin(2\pi t) % 設置位置 , 左上角 , 'Location','northwest' legend('f=t^2', 'g=sin(2\pi t)', 'Location','northwest');% y 軸標簽 ylabel('f(t)'); % x 軸標簽 xlabel('時間 (ms)');% 標題 title('時間函數')% 繪制多個圖像 hold off執行結果 :
總結
以上是生活随笔為你收集整理的【MATLAB】基本绘图 ( text 函数 | annotation 函数 | 绘制图像示例 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【MATLAB】基本绘图 ( 线条设定
- 下一篇: 【MATLAB】基本绘图 ( 图形属性