write a matlab function
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Sriram Tadavarty
on 16 Mar 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!