Getting fprintf to display two different outputs from a function on the same line.

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.

답변 (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)
The X vertex is 1 The Y vertex is 1
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

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

제품

질문:

2024년 1월 21일

댓글:

2024년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by