How can you initialize user input inside of a constructor?

조회 수: 4 (최근 30일)
mzw
mzw 2019년 4월 3일
댓글: Rena Berman 2019년 4월 4일
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
Walter Roberson
Walter Roberson 2019년 4월 3일
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...
Rena Berman
Rena Berman 2019년 4월 4일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 3일
편집: Walter Roberson 2019년 4월 3일
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".

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by