User input in an array?

조회 수: 10 (최근 30일)
Olivia Colombo
Olivia Colombo 2019년 2월 19일
댓글: madhan ravi 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