write a matlab function

6 visualizaciones (últimos 30 días)
95
95 el 16 de Mzo. de 2020
Respondida: Sriram Tadavarty el 16 de Mzo. de 2020
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

Respuesta aceptada

Sriram Tadavarty
Sriram Tadavarty el 16 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by