These are my inputs how can i use str2num in title so that i can display the values of inputs?

조회 수: 4 (최근 30일)
A=input('amplitude= ')
N=input('period= ')
I get the following errors ??? Error using ==> title at 29 Incorrect number of input arguments
Error in ==> title at 23 h = title(gca,varargin{:});
how can i solve the issue?

답변 (2개)

Walter Roberson
Walter Roberson 2015년 6월 18일
A=input('amplitude= ')
N=input('period= ')
title(sprintf('Amplitude = %f mm, Period = %f s', A, N))

Stephen23
Stephen23 2015년 6월 18일
편집: Stephen23 2015년 6월 18일
It is more much robust to use the 's' option for input, which can be used like this:
A = str2double(input('amplitude= ','s'));
N = str2double(input('period= ','s'));
title(sprintf('Amplitude = %g mm, Period = %g s', A, N))
This avoids the possibility of arbitrary code being input and executed, which is what input without the 's' option will do.

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by