Problem with custom function
Mostra commenti meno recenti
I have write this function
function BESSsize = Bsize(x,y,z)
if 0.8*z >=x+y
Bsize=(x+y)*0.8/365
elseif 0.5*x+y<= z <0.8*x+y
Bsize=z/365
else
disp("Bad sizing")
end
It dosent run here but I saved in matlab and it works in my scripts.My problem is that if i try for example to multiply and use the result for example A=Bsize(10,50,100)*365 i obtain this error:
>> Bsize(10,50,100)
Bsize =
0.1315
>> A=Bsize(10,50,100)*365
Bsize =
0.1315
Output argument "BESSsize" (and possibly others) not assigned a value in the execution with "Bsize" function.
How can i solve this?
Risposta accettata
Più risposte (1)
Hi,
It is my understanding that you are confusing between the function name “Bsize” and the variable “BESSsize” which is to be returned by the function.
In the if and elseif part you are creating a variable “Bsize” with the same name of the function and the output variable that you declared to be “BESSsize” is not being assigned any value. Therefore, you are seeing the error.
The solution is to change the “Bsize” to “BESSsize” in the "if" and "else if" part and also assign a value to "BESSsize" for the else part.
A=Bsize(10,50,100)*365
function BESSsize = Bsize(x,y,z)
if 0.8*z >=x+y
BESSsize = (x+y)*0.8/365;
elseif 0.5*x+y<= z <0.8*x+y
BESSsize = z/365;
else
disp("Bad sizing");
BESSsize = 0;
end
end
Hope it helps.
Categorie
Scopri di più su Simulink in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!