# Fprintf not showing up in function output

11 views (last 30 days)
Gurinder Punni on 21 Oct 2020
Commented: VBBV on 24 Oct 2020
Hello, I made a function that calculates the area or volume of a matrix that is linear. And, I got the math stuff down but I am not sure how to display the text so it can output a complete sentence. Here is function code:
It shows the corresponding sentence for (A) but for (B) it shows just the value of D.
function(D) = areavol(A)
R = rank(A);
[rows,col] = size(A);
D = abs(det(A));
if col == 3
word = 'parallelepiped';
else
word = 'parallelogram';
if rows > R
D = 0;
fprintf('Error,%s is not linearly independent and the area or volume is %g',word,D);
else
if col == 3
fprintf('The volume of the parallelepiped is %g cubic units',D)
else
fprintf('The area of the parallegram is %g square units',D)
end
end
end
% (A)
A = randi(10,2)
%(B)
A = fix(10*rand(3))

VBBV on 21 Oct 2020
You are closing the end differently. Try this
%if true
% code
% end
function(D) = areavol(A)
R = rank(A);
[rows,col] = size(A);
D = abs(det(A));
if col == 3
word = 'parallelepiped';
else
word = 'parallelogram';
end
if rows > R
D = 0;
fprintf('Error,%s is not linearly independent and the area or volume is %g',word,D);
else
if col == 3
fprintf('The volume of the parallelepiped is %g cubic units',D)
else
fprintf('The area of the parallegram is %g square units',D)
end
end
% (A)
A = randi(10,2)
%(B)
A = fix(10*rand(3))
##### 2 CommentsShowHide 1 older comment
VBBV on 24 Oct 2020
If it works, accept the answer by clicking accept button.

R2020b

### Community Treasure Hunt

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

Start Hunting!