0

assume (320,190) is the starting point of a bonzai expansion who will spread across the globe

bonzai(320,190)=1;

that works fine, but i want that matlab asks for the starting point while running the script, so like this:

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

but it doens't work

someone a solution?

0

1 Answer 1

1

You have two equal signs in your expression, i.e. something like x = y = z, so this can not work. I would suggest to save the input into a variable, then check if it contains valid entries, and then use this variable to start the expansion:

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

Now, I guess you hope for the user to enter something like [320,190], which is a vector with two values - however you can't be sure about that. So you might want to check, if the user entered a numeric input, and if the user supplied two numbers:

% 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

Finally, you are sure, the user entered the numbers in a correct format, and you can use this to initialize bonzai:

% Initialize bonzai
bonzai(userInput(1),userInput(2)) = 1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.