I am having trouble formatting this loop to increment my variable in a COMSOL linked Matlab Code
2 次查看(过去 30 天)
显示 更早的评论
model.param.set('Porosity', '0.1');
Originally, my value is set at a specific number, anywhere from 0.1 to 1 in increments of 0.1 for now.
However, I would like to be able to output these numbers in one loop, so I would like to increment my variable of porosity and get graphs for all the increments at once.
model.param.set('Porosity', '0.1,0.1,1.0');
I tried something like this, because that is what MATLAB uses for the time increments from Comsol, but I keep running into the same error.
Failed to evaluate expression for parameter Porosity.
Syntax error in expression.
- Expression: 0.1,0.1,1
- Subexpression: ,0.1,1
- Position: 4
Is it even possible to do what I am trying to do, and am I just going about it incorrectly?
Thank you for any help you may give me
0 个评论
回答(1 个)
Vatsal
2024-6-4
Hi,
It seems like you are trying to set the ‘Porosity’ parameter to multiple values in a loop and generate graphs for each value. However, the 'model.param.set' function in COMSOL only accepts a single value at a time.The error being encountered is because '0.1,0.1,1.0' is being interpreted as a single value, which is incorrect.
To achieve the goal, a loop in MATLAB can be used to iterate over the desired range of porosity values, setting the parameter, and generating the graph for each one.
Here is an example of how this might be done:
porosity_values = 0.1:0.1:1.0; % Define the range of porosity values
for porosity = porosity_values
model.param.set('Porosity', num2str(porosity)); % Set the porosity value
% Insert code here to solve the model and generate the graph
end
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!