簡體   English   中英

MATLAB 繪圖函數沒有足夠的輸入參數

[英]MATLAB plotting function not enough input arguments

我目前正在參加 Andrew Ng 的斯坦福機器學習課程,盡管我是 MATLAB 編程語言的新手,但我正在使用 MATLAB 完成編程作業,因為該課程需要在 Ocatave 或 MATLAB 中完成作業。 對於第一個編程作業,本課程提供 Octave/MATLAB 腳本,引導您完成練習。 我正在嘗試編寫一個 MATLAB 函數來繪制 x 和 y 變量的數據,但是,我繼續遇到相同的錯誤,並開始尋找解決方案。 我有一個正在處理的 plotData.m 文件,這是我放在一起的代碼:

function plotData(x, y)
%PLOTDATA Plots the data points x and y into a new figure 
%   PLOTDATA(x,y) plots the data points and gives the figure axes labels of
%   population and profit.

figure; % open a new figure window
hold on;

% ====================== YOUR CODE HERE ======================
% Instructions: Plot the training data into a figure using the 
%               "figure" and "plot" commands. Set the axes labels using
%               the "xlabel" and "ylabel" commands. Assume the 
%               population and revenue data have been passed in
%               as the x and y arguments of this function.
%
% Hint: You can use the 'rx' option with plot to have the markers
%       appear as red crosses. Furthermore, you can make the
%       markers larger by using plot(..., 'rx', 'MarkerSize', 10);

plot(x, y, 'rx');
xlabel('population (in tens of thousands)');
ylabel('profit (in $10,000s)');

hold off;

% ============================================================

end

每次運行此腳本時,我都會收到一條錯誤消息,指出“輸入參數不足。 plotData 錯誤(第 19 行)plot(x, y, 'rx');'。 這是一個相當含糊的錯誤消息,我不確定如何解釋這里的錯誤。 我不明白為什么在這個例子中我沒有足夠的輸入參數,因為函數顯式地接受 x 和 y 並使用每個來繪制函數定義的數據。 任何幫助將不勝感激。

我正在使用 MATLAB 版本 9.6.0.1114505 (R2019a) 更新 2

我在運行“plotData.m”時遇到同樣的錯誤,請嘗試運行“ex1.m”而不是“plotData.m”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM