Passing values from an array to a function
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Varun
2023 年 9 月 1 日
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:
- Look at the function definitions: Check that the functions “VesselEvacuation” and “CCVP” have the correct amount of input arguments and output variables.
- 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.
- 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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!