[英]How to solve the Error: x undefined in octave
我正在嘗試 plot 數據。 首先,我從文件中加載數據
data = load('ex1data1.txt'); % read comma separated data
X = data(:, 1); y = data(:, 2);
m = length(y); % number of training examples
然后我調用了 function plotData
function figure=plotData(x, y)
figure; % open a new figure window
if(is_vector(x) && is_vector(y))
figure=plot(x,y,'rx',MarkerSize,10);
xlabel('Profit in $10,000s');
ylabel('Population of city in 10,000s');
endif
endfunction
但我收到一個錯誤。 其中說: x 未定義提前謝謝你。
問題出在以下語句中:
X = data(:, 1); y = data(:, 2);
你已經定義了X
變量但是當你調用
plotData(x, y)
你正在使用小寫 X
我認為如果更改語句: plotData(X, y)
將解決您的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.