write a matlab function

6 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by