Compare commits
3 Commits
c9da63730b
...
c535ee08c4
| Author | SHA1 | Date |
|---|---|---|
|
|
c535ee08c4 | |
|
|
5433b8ca49 | |
|
|
bd2abeae3b |
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Enrico Lumetti
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
12
objects.m
12
objects.m
|
|
@ -1,3 +1,5 @@
|
||||||
|
clear;
|
||||||
|
|
||||||
% instantiate an object of type BasicClass (see BasicClass.m)
|
% instantiate an object of type BasicClass (see BasicClass.m)
|
||||||
obj = BasicClass;
|
obj = BasicClass;
|
||||||
|
|
||||||
|
|
@ -15,6 +17,12 @@ obj.roundOff();
|
||||||
v = BasicClass(42);
|
v = BasicClass(42);
|
||||||
assert(v.Value == 42);
|
assert(v.Value == 42);
|
||||||
|
|
||||||
|
% all properties can be enumerated
|
||||||
|
assert(isequal(properties(v), {'Value'}'));
|
||||||
|
|
||||||
|
% and all methods
|
||||||
|
assert(isequal(methods(v), {'BasicClass', 'multiplyBy', 'plus', 'roundOff'}'));
|
||||||
|
|
||||||
% object arrays are presto supported
|
% object arrays are presto supported
|
||||||
objs(1) = BasicClass(44);
|
objs(1) = BasicClass(44);
|
||||||
objs(2) = BasicClass(33);
|
objs(2) = BasicClass(33);
|
||||||
|
|
@ -26,7 +34,7 @@ assert(isequal( [objs.Value], [44 33] ));
|
||||||
assert(isequal( {objs.Value}, {44, 33} ));
|
assert(isequal( {objs.Value}, {44, 33} ));
|
||||||
|
|
||||||
% operator overloading
|
% operator overloading
|
||||||
obj + objs(1);
|
v + v;
|
||||||
|
|
||||||
% also works for object arrays
|
% also works for object arrays
|
||||||
[objs] + [objs]
|
[objs] + [objs];
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,36 @@
|
||||||
|
clear;
|
||||||
|
|
||||||
|
model_name = "rc_circuit";
|
||||||
|
load_system(model_name);
|
||||||
|
|
||||||
|
stopTime = 5;
|
||||||
|
V_in = 10;
|
||||||
|
R = 1e3;
|
||||||
|
C = 1e-4;
|
||||||
|
freq = 1;
|
||||||
|
timestep = 0.01;
|
||||||
|
|
||||||
|
ts = (0:timestep:stopTime)';
|
||||||
|
vs = sin(2*pi*freq * ts);
|
||||||
|
|
||||||
|
sim_in = Simulink.SimulationInput(model_name);
|
||||||
|
sim_in = sim_in.setModelParameter("R", num2str(R));
|
||||||
|
sim_in = sim_in.setModelParameter("C", num2str(C));
|
||||||
|
sim_in = sim_in.setModelParameter("StopTime", num2str(stopTime));
|
||||||
|
|
||||||
|
% note: to be compatible with port size, ts must be a column vector
|
||||||
|
sim_in = sim_in.setExternalInput([ts, vs]);
|
||||||
|
|
||||||
|
% simulate
|
||||||
|
res = sim(sim_in);
|
||||||
|
|
||||||
|
figure;
|
||||||
|
subplot(2, 1, 1);
|
||||||
|
plot(ts, vs);
|
||||||
|
xlabel('Time (seconds)');
|
||||||
|
ylabel('V_{in} (Volt)');
|
||||||
|
|
||||||
|
subplot(2, 1, 2);
|
||||||
|
plot(res.yout{1}.Values);
|
||||||
|
|
||||||
|
close_system(model_name);
|
||||||
Loading…
Reference in New Issue