在MATLAB中建立笛卡爾座標系


當在MATLAB中構建圖形元件時,笛卡爾座標系會自動新增;但是,MATLAB有一個函式,即'axes()'函式,可以執行特定任務。此函式可在圖形中生成笛卡爾座標系。當單個圖形元件需要多個笛卡爾平面時,它非常有用。在本教程中,我們將探討如何在MATLAB中建立笛卡爾座標系。

現在,讓我們透過示例程式討論'axes'函式的不同語法來建立笛卡爾座標系。

(1). 建立預設笛卡爾座標系

在MATLAB中,我們可以使用'axes'函式的以下語法來建立一個預設的笛卡爾座標系:

a = axes;

考慮以下MATLAB程式來了解此語法的實現。

Matlab 示例 (1)

% MATLAB program for creating default cartesian axes
% Create the default cartesian axes
a = axes;

輸出

(2). 建立具有自定義屬性的笛卡爾座標系

'axes'函式的以下語法用於建立具有自定義屬性的笛卡爾座標系。

a = axes(Name, Value);

此處,名稱-值對指定笛卡爾座標系的自定義屬性以更改其外觀。

考慮以下MATLAB程式來建立具有自定義屬性的笛卡爾座標系。

Matlab 示例 (2)

% MATLAB program for creating cartesian axes with custom properties
% Create the cartesian axes with custom properties
% Example axes 1
A1 = axes('Position', [0.25 0.25 0.5 0.5], 'LineWidth', 3, 'FontSize', 13); title('Axes 1');

% Example axes 2
A2 = axes('Position', [0.5 0.4 0.3 0.3], 'LineWidth', 1, 'FontSize', 9); title('Axes 2');

輸出

(3). 在父容器中建立笛卡爾座標系

'axes'函式的以下語法用於在指定的父容器中建立笛卡爾座標系:

a = axes(parent, Name, Value);

以下MATLAB程式演示了此語法的實現。

Matlab 示例 (3)

% MATLAB code for creating cartesian axes within a UI figure
% Create a UI figure window
fig = uifigure;

% Create cartesian axes within the figure window
a = axes(fig, 'Position', [0.2 0.2 0.4 0.4]);

輸出

(4). 在每個笛卡爾座標系周圍新增邊框

語法

在MATLAB中,'axes'函式的以下語法用於在笛卡爾座標系周圍新增邊框:

a = axes(---, 'Box', 'on');

以下MATLAB程式演示了此語法的實現。

Matlab 示例 (4)

% MATLAB program to add boxes around cartesian axis
% Create a cartesian axes with boxes around it
a = axes('Position', [0.2 0.2 0.5 0.5], 'Box', 'on');

輸出

結論

在MATLAB中,有一個內建函式'axes',它可以根據不同的用例具有不同的語法。我們在本文的上述部分解釋並演示了'axes'函式的不同語法。

更新於:2023年9月6日

73 次檢視

啟動您的職業生涯

完成課程獲得認證

開始
廣告