フィルターのクリア

check whather user input is given or Not and check the validation

1 回表示 (過去 30 日間)
ORUGANTI SIVAMURALIKRISHNA
ORUGANTI SIVAMURALIKRISHNA 2020 年 6 月 8 日
I wrote a code and while executing it sometimes i will skip some inputs then it will continue to second line, whle computing it will show error and exit. so i want to eliminate ot by making sure the user given input and show him all the given inputs and giving cahncce to change them if required then continue can you please help

回答 (2 件)

Dhanush Bejjarapu
Dhanush Bejjarapu 2020 年 6 月 8 日
Do you mean that we need to give input for few parameters and they should be used for the next steps?
  1 件のコメント
ORUGANTI SIVAMURALIKRISHNA
ORUGANTI SIVAMURALIKRISHNA 2020 年 6 月 10 日
if input is not given then ask for the input again or exit the program

サインインしてコメントする。


Walter Roberson
Walter Roberson 2020 年 6 月 8 日
function varargout = YourFunction(varargin)
argnames = {'x', 'y', 'n'};
for K = 1 : length(argnames)
if nargin < K || isempty(varargin{K}) || any(isnan(varargin{K}(:)))
new_parameter = input( sprintf('Enter a value for %s ', argnames{K} ) );
newargs = varargin;
newargs{K} = new_parameter;
[varargout{:}] = YourFunction(newargs{L});
return
end
end
%if you got here, your argument validation passed, so do your regular computation
end
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 6 月 14 日
YourFunction(nan, 123)
ORUGANTI SIVAMURALIKRISHNA
ORUGANTI SIVAMURALIKRISHNA 2020 年 6 月 15 日
rised line command : Enter a value for x and input is given as 5
reply as error:
Expected one output from a curly brace or dot indexing expression, but there were 0 results.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by