Clear Filters
Clear Filters

Passing values from an array to a function

2 views (last 30 days)
I am trying to use functions to simplify a model. As part of this work I have used a function to calculate a value which is then output in the main code and saved to an array. From there a second function is required to take the value just entered into the matrix and use it to calculate a further value.
for i=1:n
Pressure_vessel(1,i) = VesselEvacuation(P_intial, S, LR, radius, height, Vol_sample, time_plot) * 100; % *100 to convert to Pa
vessel(1,i) = Pressure_vessel(1,i);
mass_plot(1,i) = CCVP(vessel(1,i), delHvap, R, T1, T2, Vol_sample, RMM);
t(1,i+1) = time_plot + 1;
time_plot = time_plot + 1;
mass_plot(1,i+1) = 0;
end
Upon trying this however I get the error:
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Does anyone know a solution?
edit: swapped n for i
  5 Comments
Thomas Bainbridge
Thomas Bainbridge on 3 Aug 2022
Pressure_vessel and vessel are the same value and was just being used to work around an issue that was coming up - I'll give it a go again with the vessel = Pressure_vessel line and subsequent adjustments.
I think I may have managed to solve the issue with a messy solution. Once I've confirmed the results are correct I'll update this post with a neatened solution.
Dyuman Joshi
Dyuman Joshi on 3 Aug 2022
It will be better if you post your whole code.

Sign in to comment.

Answers (1)

Varun
Varun on 1 Sep 2023
Hello!
The error you got indicates that there may be a problem with the syntax or delimiters in your code. To resolve this error, look for any mismatched parentheses or brackets in your code.
According to the code sample you gave, the problem appears to be occurring in one of the methods you are calling i.e. VesselEvacuation or CCVP. Without the full script, I can’t pinpoint exactly what may be going wrong. However, when invoking these functions, ensure that you use the right syntax and that the functions are properly defined.
Here are a few things you can do to fix the problem:
  1. Look at the function definitions: Check that the functions VesselEvacuationand CCVP have the correct amount of input arguments and output variables.
  2. Examine the function calls: When invoking the functions, make sure you use the correct syntax. If there are several arguments, the function name should be followed by parenthesis (), and the input arguments should be provided within the parentheses, separated by commas.
  3. Examine the variable names: Before calling the functions, ensure that all variables (P_intial, S, LR, radius, height, Vol_sample, time_plot, vessel”, etc.) are properly declared and have the correct values allocated to them.
You should be able to discover and rectify any errors producing the "Invalid expression" error in your code by carefully reviewing the syntax, function definitions, and variable names.
Hope this helps!
Thanks,
Varun

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!