User input in an array?

12 次查看(过去 30 天)
Olivia Colombo
Olivia Colombo 2019-2-19
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.

回答(1 个)

madhan ravi
madhan ravi 2019-2-19
Use input() with 's' which refers to a string. https://www.mathworks.com/help/matlab/ref/input.html#btt5vtc-2
  1 个评论
madhan ravi
madhan ravi 2019-2-19
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)
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by