필터 지우기
필터 지우기

HAVING TROUBLE WITH PLOTTTING

조회 수: 2 (최근 30일)
My mee
My mee 2021년 7월 13일
댓글: Cris LaPierre 2021년 7월 14일
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
Cris LaPierre
Cris LaPierre 2021년 7월 14일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 7월 14일
% 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
Cris LaPierre
Cris LaPierre 2021년 7월 14일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by