MATLAB Answers

I want to display result in different names.

3 views (last 30 days)
Sandun Munasinghekankanamge
Commented: Rena Berman on 23 Sep 2021
function[result] = Geometric_cal(var1,var2,indicator)
% indicator = 1 is for Area of a Rectangle
% indicator = 2 is for Volume of a Cylinder
%indicator = 3 is for volume of a 4-sided Pyramid with equal sides
%indicator = 5 is for Volume of a Cone.
if indicator == 1
result = var1 * var2;
elseif indicator == 2
result = var1 * pi * var262;
elseif indicator == 3
result = (var1^2 * var2)/3;
elseif indicator == 4
result = pi * var2^2 * (var1/3);
else
result = ' Test your indicator';
end
how do I display those reults above in different names. as an example if my indicator is 1 I want to display my result as "Area of a rectangle" not like result.

Answers (2)

KSSV
KSSV on 2 Aug 2021
Read about fprintf.
function[result] = Geometric_cal(var1,var2,indicator)
% indicator = 1 is for Area of a Rectangle
% indicator = 2 is for Volume of a Cylinder
%indicator = 3 is for volume of a 4-sided Pyramid with equal sides
%indicator = 5 is for Volume of a Cone.
if indicator == 1
result = var1 * var2;
fprintf('Area of a Rectange = %f\n',result) ;
elseif indicator == 2
result = var1 * pi * var262;
fprintf('Volume of a Cylinder = %f\n',result) ;
elseif indicator == 3
result = (var1^2 * var2)/3;
fprintf('volume of a 4-sided Pyramid with equal sides = %f\n',result) ;
elseif indicator == 4
result = pi * var2^2 * (var1/3);
fprintf('Volume of a Cone = %f\n',result) ;
else
result = ' Test your indicator';
end

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by