Getting fprintf to display two different outputs from a function on the same line.
Ältere Kommentare anzeigen
function [xVertex,yVertex] = PolyVertex(a, b, c)
%PolyVertex comoute the X and Y vertex of any polynomial given a, b, and c.
% Get a, b and c from y = ax^2 + bx + c and plug them in to get the x and y vertex
xVertrex = -(b/(2*a));
yVertex = (a*(xVertex^2)) + (b*xVertex) + c
end
% initialize a, b, and c
a = 3;
b = -6;
c = 4;
% call your function
% assign both outputs
PolyVertex(a, b, c);
% call fprintf to display the results in a single line
% use %d as the placeholder
% include descriptive text
fprintf("The X vertex is %d The Y vertex is %d " PolyVertex(a, b, c))
I'm having trouble getting the last line to print xVertex and yVertex.
Antworten (1)
% initialize a, b, and c
a = 3;
b = -6;
c = 4;
% call PolyVertex and assign both outputs
[xV,yV] = PolyVertex(a, b, c);
% display the result
fprintf("The X vertex is %d The Y vertex is %d ", xV, yV)
function [xVertex,yVertex] = PolyVertex(a, b, c)
%PolyVertex comoute the X and Y vertex of any polynomial given a, b, and c.
% Get a, b and c from y = ax^2 + bx + c and plug them in to get the x and y vertex
% xVertrex = -(b/(2*a)); % fixed typo "xVertrex"
xVertex = -(b/(2*a));
yVertex = (a*(xVertex^2)) + (b*xVertex) + c;
end
1 Kommentar
DYLAN
am 21 Jan. 2024
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!