2015-12-16 30 views
0

假設(320190)是bonzai擴張的起點,誰就會在全球範圍內讓matlab腳本詢問輸入值?

bonzai(320,190)=1; 

工作正常展開,但我想,MATLAB要求爲出發點運行的腳本時,所以像這樣的:

bonzai=input('give lon,lat of the bonzai tree')=1 

但它好好嘗試工作

有人的解決方案?

回答

1

您的表達兩個等號,即像x = y = z,所以這是行不通的。我建議將輸入保存到一個變量,然後檢查它是否包含有效條目,然後使用這個變量來啓動擴張:

% Get user input 
userInput = input('Give lon,lat of the bonzai tree: '); 

現在,我想你希望用戶輸入類似[320,190] ,這是一個有兩個值的矢量 - 但是你不能確定這一點。所以,你可能要檢查,如果用戶輸入一個數字的輸入,如果用戶提供的兩個數字:

% Check if the input is numeric, i.e. a scalar, vector or matrix of numbers 
if ~isnumeric(userInput) 
    error('Please enter numbers, nothing else!') 
end 
% Check if the input contains exactly two numbers 
if numel(userInput) ~= 2 
    error('Please specify two numbers: lon and lat') 
end 

最後,你肯定的是,用戶以正確的格式輸入的號碼,並且可以使用這個初始化bonzai

% Initialize bonzai 
bonzai(userInput(1),userInput(2)) = 1;