How can I calculate block parameters from mask parameters?
Mostrar comentarios más antiguos
The Goal:
I have a subsystem which I now want to control over a mask. The mask should allow me to chose between two materials and give a thickness and radius of a cylinder. In the subsystem I then want to use the material choice to define the relevant material parameters (e.g. in a "if material == 1, then parameters =... " statement) and I want to pass on the thickness and radius, however they are not direct parameters for a block in the code (so I can't just promote them). Instead I want to do calculations with them, e.g. I have an impedance that calculates from Z=rho*pi*r^2. Rho should be defined by the Material choice and r should be given in the mask in an edit block. See below for what I picture for the mask:

Now what I need to calculate from these is some further values. Before I created the subsystem I did this in the InitFunc of the model.
What I have currently:
classdef piezoElement_mask
methods(Static)
% Following properties of 'maskInitContext' are available to use:
% - BlockHandle
% - MaskObject
% - MaskWorkspace: Use get/set APIs to work with mask workspace.
function MaskInitialization(~)
end
% Use the code browser on the left to add the callbacks.
function material(mat)
if isequal(mat, 1)
g33=0.0142188;
g31=-0.0333414;
c33D=1.362e11;
c11D=7.268e10;
h33=g33*c33D;
h31=g31*c11D;
eps33S=9.249e-9;
rho=14672.908;
end
if isequal(mat,2)
c33D=1.295e11;
c11D=8.587e10;
h33=1.302e9;
h31=-1.684e9;
eps33S=8.711e-9;
rho=17435.538;
end
end
function thickness(th)
d = th*1e-3;
end
function radius(rd)
r = rd*1e-3;
A=pi*r^2;
C0=A*eps33S/d;
Z33 = A*sqrt(c33D/rho)*rho;
t33=d/sqrt(c33D/rho) ;
Z11 = 2*pi*d*r*sqrt(c11D/rho)*rho;
t11=2*r/sqrt(c11D/rho) ;
end
end
end
There's probably a better way to do this, also this right now doesn't work. I always get an error for thickness and radius (material seems to be fine?) and my blocks in the subsystem still use the parameters stored in the MATLAB variable browser, not the updated values I try to give here.

Can anyone help? I've found loads of information on passing on parameters, but only for when you use the parameter directly and not if you want to use them for calculations first.
Respuesta aceptada
Más respuestas (1)
Categorías
Más información sobre Subsystems en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!