How can you initialize user input inside of a constructor?

Example I want the x value to user input but i'm not sure how to get it to work
classdef name
properties
getName = input("Whats your name")
end
methods
function obj = name(x)
getName = x
end
end
end

2 comentarios

Very odd. I was positive that someone had asked a question about constructors and input() just a short time ago, and that someone (Stephen perhaps) responded with a nice analysis of good reasons why that should never be done. But I can't seem to find that question now..
I wonder if someone did not like the response they received and deleted the question...
(Answers Dev) Restored edit

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Abr. de 2019
Editada: Walter Roberson el 3 de Abr. de 2019
You cannot get it to work. Constructors are the wrong place to put input() requests. Any input() request in a constructor would do the Wrong Thing, for very reasonable definitions of "Wrong Thing".

Más respuestas (0)

Categorías

Más información sobre Functions en Centro de ayuda y File Exchange.

Preguntada:

mzw
el 3 de Abr. de 2019

Comentada:

el 4 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by