Write a function StudentInfo()with no input argument and no output argument. Inside the function, ask the user to enter: first name, last name, student ID, and GPA. The function stores all these inputs into a single cell array variable and display the content in the following format:
>> StudentInfo()
>> Please enter the First Name: Mark
>> Please enter the Last Name: Twain
>> Please enter the ID: 12345678
>> Please enter the GPA: 3.10
>> Below are what you have entered:
Name: Mark Twain
UID: 12345678
GPA: 3.10

 採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 16 日

1 投票

Hi Jiaqi,
I suggest you to go through MATLAB onramp course https://www.mathworks.com/learn/tutorials/matlab-onramp.html , which provides all the necessary details to quick start programming in MATLAB.
For your question, the following links can help you write the code:
Follow the above links and you could come up with a similar output code as below:
function StudentInfo()
details = cell(4,1);
details{1} = input('Please enter the First Name:','s');
details{2} = input('Please eneter the Last Name:','s');
details{3} = input('Please enter the ID:','s');
details{4} = input('Please enter the GPA:','s');
% Display the details
disp("Name: " + cellstr(details{1}) + " " + cellstr(details{2}))
disp("UID: " + num2str(details{3}))
disp("GPA: " + num2str(details{4}))
end
Hope this helps.
Regards,
Sriram

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2019b

質問済み:

95
2020 年 3 月 16 日

回答済み:

2020 年 3 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by