MATLAB: When i run the script without the fprintf line i get the right answer. however when i apply the fprintf line i get the error “index exceeds matrix dimensions.” how do i fix this? (the functions are in different .m files obviously)

fprintfindex exceeds matrix dimensions

SAS_TriangleArea Function
%%%%%%%%%%%%%%%%%%%%%%%%%
function [ triangleArea ] = SAS_TriangleArea( a, b, alpha )
%SAS_TriangleArea Finds Triangle Area by using side-angle-side
triangleArea = (1/2)*a*b*sind(alpha);
end
%%%%%%%%%%%%%%%%%%%%%%%%%
%SSS_TriangleArea Function
function [ triangleArea ] = SSS_TriangleArea( a, b, c )
%SSS_TriangleArea computes area of side-side-side triangle
S = (a + b + c)/2;
triangleArea = sqrt(S*(S-a)*(S-b)*(S-c));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Test Case 1
w = 1;
x = 1;
z = 1;
y = sqrt(2);
alpha = 90;
triangle1 = SAS_TriangleArea(w,x,alpha);
triangle2 = SSS_TriangleArea(x,y,z);
triangleArea = triangle1 + triangle2;
fprintf('The area for Test Case 1 is: %3.2f', triangleArea)

Best Answer

Works for me:
>> TriangleArea_Test
The area for Test Case 1 is: 1.00
Try this:
which fprintf
Maybe you have a variable named "fprintf" that is shadowing the built-in fprintf function. If so, clear it first.
SIDE NOTE: You are going to want to put a newline at the end of your fprintf format. E.g.,
fprintf('The area for Test Case 1 is: %3.2f\n', triangleArea) <-- Added the \n