Borrar filtros
Borrar filtros

input a 1*3 vector

1 visualización (últimos 30 días)
Khalid AL Harthi
Khalid AL Harthi el 11 de Nov. de 2015
Editada: Thorsten el 11 de Nov. de 2015
how can I make the user inputs an array of 1*3 dimensions for example x=input('your guess') x= [# # #]

Respuestas (3)

Stalin Samuel
Stalin Samuel el 11 de Nov. de 2015

Walter Roberson
Walter Roberson el 11 de Nov. de 2015
while true
xs = input('enter your guess (a list of three numbers)', 's');
xs = regexprep(xs, '^\[(.*)\]', '$1');
s = regexp(xs, '(\s|,)+', 'split');
if length(s) ~= 3
warning('Wrong number of entries, need 3');
continue;
end
x = str2double(s);
if any(isnan(x))
warning('Something was not a number!');
continue;
end
break;
end

Thorsten
Thorsten el 11 de Nov. de 2015
Editada: Thorsten el 11 de Nov. de 2015
Use brackets when entering the input
>> x=input('your guess')
your guess[1 2 3]
x =
1 2 3

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by