Clear Filters
Clear Filters

Error using (function_name). Too many output arguments.

32 views (last 30 days)
I'm having some issues with this code:
fluido = "aria"
fluido = "aria"
for temp = 15:0.1:1500
vettore_cp(i)=calcolo_cp(temp, fluido);
Error using solution>calcolo_cp
Too many output arguments.
title("grafico del calore specifico in funzione della temperatura")
xlabel("temperatura [°C]")
ylabel("calore specifico [J/kg*K]")
The program should plot a diagram using the function calcolo_cp that calculates the specific heat and uses as inputs the temperature of the fluid and what type of fluid we want to examinate ( in this case "aria", "air" in english).
The function calcolo_cp is in the same folder and seems to work fine, the code of this function is:
function calcolo_cp(T,fluido)
if strcmp(fluido, "aria")
elseif strcmp(fluido, "gas")
coeff=[1000.61 0.482759e-1 0.462906e-3 -0.454035e-6 0.129112e-9;
1013.71 0.641882e-1 0.452287e-3 -0.444350e-6 0.125765e-9];
for i = 1:5
elementi_cp(i) = coeff(indice_riga,i)*T^(i-1);
cp = sum(elementi_cp)
I'm here if you need more information about my code.
Thank you all.

Answers (2)

Stephen23 on 24 Apr 2024
Edited: Stephen23 on 24 Apr 2024
You did not define the function to return any output arguments:
function calcolo_cp(T,fluido)
If you intended to return e.g. CP then you need to tell MATLAB that:
function cp = calcolo_cp(T,fluido)
The documentation explains how to define functions:

Deepu on 24 Apr 2024
The error message "Too many output arguments" typically occurs when the number of variables you are trying to assign the outputs of a function to does not match the number of output arguments the function actually returns.
In your code, the function calcolo_cp is called inside a loop, and you are trying to assign its output to temp, which is likely causing the error. The calcolo_cp function seems to only calculate a single output, cp, but your code expects two outputs (temp and cp).
To fix this issue, you need to ensure that you are assigning the correct number of output arguments from the calcolo_cp function. If you only need cp, you can modify your loop as follows:
for temp = 15:0.1:1500
cp = calcolo_cp(temp, fluido);
This way, you're only assigning the output cp to vettore_cp(i), which should resolve the "Too many output arguments" error.
Stephen23 on 24 Apr 2024
"The calcolo_cp function seems to only calculate a single output, cp, but your code expects two outputs (temp and cp)."
Really? It seems like your AI engine does not understand MATLAB code syntax.
Deepu on 25 Apr 2024
My interpretation was incorrect. The error message indeed indicates that the function call is returning too many output arguments than expected.
Thank you for bringing this to my attention, and I appreciate your patience.

Sign in to comment.


Find more on Fluid Dynamics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!