HAVING TROUBLE WITH PLOTTTING

1 view (last 30 days)
My mee
My mee on 13 Jul 2021
Commented: Cris LaPierre on 14 Jul 2021
Can someone help me with my code because it says error in plotlump here is the code
FOR LUMPSUM.M
while(1)
[val,Principal,Number,Interest] = inputvalues;
if(val(1) == 0)
disp('Entered Principal Amount is wrong ');
disp('Please enter the details again ');
end
if(val(2) == 0)
disp('Entered Number of years is wrong ');
disp('Please enter the details again ');
end
if(val(3) == 0)
disp('Entered Rate of Interest is wrong ');
disp('Please enter the details again ');
end
if(sum(val) == 3)
break;
end
end
% function call to plotlump function
plotlump(Principal,Number,Interest);
FOR INOUTVALUES.M
function [e,P,N,i] = inputvalues
% Taking input from the user
P = input('Enter the Prinicipal Amount Invested : ');
N = input('Enter number of years : ');
i = input('Enter the rate of interest : ');
% Then this checks if there is an error
e = errorcheck(P,N,i);
end
FOR ERRORCHECK.M
function value = errorcheck(Principal,Number,Interest)
% If they are valid , then value holds as 1 meaning they are valid while
% value holds 0 meaning they are wrong
value = [1,1,1];
if(Principal <= 0)
value(1) = 0;
end
if(Number <= 0)
value(2) = 0;
end
if(or(Interest < 0,Interest > 100))
value(3) = 0;
end
end
FOR PLOTLUMP.M
function plotlump(Principal,Number,Interest)
% This loop will calculate value of S
S = zeros(1,Number);
for N = 1:Number
S(N) = (Principal * (1 + (Interest/100))^N);
end
Im having trouble with plotlump because everytime I enter the code it's saying "Not enough input arguments.
Error in plotlump (line 6)
S = zeros(1,Number);"
  1 Comment
Cris LaPierre
Cris LaPierre on 14 Jul 2021
Have you removed something from your plotlump code? S = zeros(1,Number) is not on line 6.
When I put this all together, it runs without error for me. I've simplified the code to run here.
while(1)
val=[1 1 1];
Principal=1000;
Number = 1;
Interest=6.5;
% [val,Principal,Number,Interest] = inputvalues;
if(val(1) == 0)
disp('Entered Principal Amount is wrong ');
disp('Please enter the details again ');
end
if(val(2) == 0)
disp('Entered Number of years is wrong ');
disp('Please enter the details again ');
end
if(val(3) == 0)
disp('Entered Rate of Interest is wrong ');
disp('Please enter the details again ');
end
if(sum(val) == 3)
break;
end
end
% function call to plotlump function
plotlump(Principal,Number,Interest)
S = 1065
function plotlump(Principal,Number,Interest)
% This loop will calculate value of S
S = zeros(1,Number);
for N = 1:Number
S(N) = (Principal * (1 + (Interest/100))^N)
end
end

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 14 Jul 2021
% Here is a slightly edited/fixed version that works ok.
while(1)
[val,Principal,Number,Interest] = inputvalues;
if(val(1) == 0)
disp('Entered Principal Amount is wrong ');
disp('Please enter the details again ');
end
if(val(2) == 0)
disp('Entered Number of years is wrong ');
disp('Please enter the details again ');
end
if(val(3) == 0)
disp('Entered Rate of Interest is wrong ');
disp('Please enter the details again ');
end
if(sum(val) == 3)
break;
end
end
% function call to plotlump function
S=plotlump(Principal,Number,Interest);
function [e,P,N,i] = inputvalues
% Taking input from the user
P = input('Enter the Prinicipal Amount Invested : ');
N = input('Enter number of years : ');
i = input('Enter the rate of interest : ');
% Then this checks if there is an error
e = errorcheck(P,N,i);
end
function value = errorcheck(Principal,Number,Interest)
% If they are valid , then value holds as 1 meaning they are valid while
% value holds 0 meaning they are wrong
value = [1,1,1];
if(Principal <= 0)
value(1) = 0;
end
if(Number <= 0)
value(2) = 0;
end
if(or(Interest < 0,Interest > 100))
value(3) = 0;
end
end
function S =plotlump(Principal,Number,Interest)
% This loop will calculate value of S
S = zeros(1,Number);
for N = 1:Number
S(N) = (Principal * (1 + (Interest/100))^N);
end
end
  1 Comment
Cris LaPierre
Cris LaPierre on 14 Jul 2021
I guess my point was that I didn't have to edit anything in the code the OP shared for it to work. I only modified it so it could run in Answers and produce an ouput, showing that I am not able to reproduce the input argument error to plotlump.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!