MATLAB Answers


User input in an array?

Asked by Olivia Colombo on 19 Feb 2019
Latest activity Commented on by madhan ravi
on 19 Feb 2019
I'm asking for the user to input a sentence in my function and then it reverses the sentence, but there's an error on the line that asks for input. Not sure what I'm doing wrong? I've attached the function.


Sign in to comment.


1 Answer

madhan ravi
Answer by madhan ravi
on 19 Feb 2019

Use input() with 's' which refers to a string.

  1 Comment

madhan ravi
on 19 Feb 2019
backward() % no input argument is required because all are defined inside the function
function backward() % function definition
a = input('Write a sentence to be reversed: ','s');
b = split(a); % Is this necessary?
c = reverse(a);
fprintf('Your sentenced reversed is: %s\n',c)

Sign in to comment.