似乎我有一個名爲「annotation」的變量和內置的MATLAB函數「annotation」中的一個變量名稱相沖突。MATLAB名稱衝突:「錯誤的參數數量」
在我的函數中,我加載一個包含變量註釋的.mat文件,然後嘗試將它用作另一個函數的參數。一個最小的工作示例如下:
function test()
filenames = { 'file1.mat', 'file2.mat', 'file3.mat' };
for i = 1:numel(filenames)
in_file = char(filenames{i});
out_file = strrep(in_file, '.mat', '_out.mat');
prepare(out_file); % do something with the out file
load(out_file); % contains one variable named "annotation"
which annotation % just to be sure
other_function(annotation);
end
end
function prepare(filename)
annotation = rand(25, 1);
save(filename);
end
function other_function(annotation)
whos % just a stub - see whether it has been called
end
現在,在我的功能準備我確信該文件包含一個名爲「註釋」的變量。當我將它加載到主函數的循環中時,「which」命令告訴我它作爲變量存在,但在other_function的調用中,MATLAB試圖調用函數「annotation」:
註解是一個變量。
???使用錯誤==>註釋在71
沒有足夠的輸入參數
錯誤==>測試在14
other_function(annotation);
我很困惑,因爲我使用的變量名「註釋」在我的程序的幾個部分,也作爲函數調用的參數。我能想象的唯一解釋是MATLAB以某種方式預編譯我的代碼 - 在「編譯時」,變量「註釋」不可見。但是,在運行時發現可以從「which」命令的輸出中看到。
任何幫助將不勝感激!提前謝謝了。
注意:我正在使用MATLAB 7.12.0(R2011a)。
即使你有在其他情況下取得成功,所有我會做的是改變你的變量annotation.Well的名字,我無法看到註釋作爲聲明中的代碼中的變量。正如我理解的Matlab,它只是覆蓋所有內容而不詢問,因爲它是腳本語言。你可以通過調試器去看看「哪個」裏面有什麼註釋嗎? –
調試器會說註釋是一個變量,如果你在調試器中鍵入'annotation',它會評估它,而不會出錯。 – Richante