- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
function handle as boundary condition
12 次查看(过去 30 天)
显示 更早的评论
sorry if this is a very silly question as I am quite new using matlab. So I apologise in advance.
I have a vector with accelerations corresponding to time intances. I need to use a interpolation function to interpolate values of accelerations at different times, and I need to pass this function as boundary condition in specific edges.
len=length(accel_filt);
%Create a time vector with the total length of the vector of acceleration
%measure every time instance
tlist=linspace(0,len,len);
%Create the interpolation function to use as boundary condition
bc = griddedInterpolant(tlist,accel_filt',"linear","nearest");
%--APPLY BOUNDARY CONDITION TO INNER EDGES-- 19/04/23----------------------
for j = 1:numel(edges) %for every value store in perimeter
edge=edges(j);
applyBoundaryCondition(modelTwoDomain,"dirichlet","Edge",edge,"u",@bcfundcD);
end
function defined at the end of code:
function bc=bcfundcD(location,bc)
state.u = bc(location.x);
end
What am I doing wrong?
13 个评论
回答(1 个)
Avni Agrawal
2023-11-16
Hi,
I understand that you are trying to pass function handle as an argument to the ‘applyBoundaryCondition’ function in MATLAB. Here is an example of how you can achieve this:
Method 1:
bcfundcD = @(location, state) yourCustomBoundaryCondition(region, state);
% Apply the boundary condition using the function handle
applyBoundaryCondition(model, 'face', 1:4, 'u', bcfundcD);
‘yourCustomBoundaryCondition’ is a function that you have defined to implement your specific boundary condition logic. The ‘bcfoundcD’ function handle is created using an anonymous function that calls ‘yourCustomBoundaryCondition’ with the appropriate arguments. i.e location, state.
Method 2:
% Define the named function
function bcfundcD = yourCustomBoundaryCondition(region, state)
% Implement your boundary condition logic here
% ...
end
% Apply the boundary condition using the function handle
applyBoundaryCondition(model, 'face', 1:4, 'u', @yourCustomBoundaryCondition);
In this case, the ‘@’ symbol is used to create a function handle to the named function ‘yourCustomBoundaryCondition’.
Take a look at this documentation for better understanding:
I hope this helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!