Compare commits

..

3 Commits

Author SHA1 Message Date
Enrico Lumetti c535ee08c4 Update license 2021-08-09 15:36:42 +02:00
Enrico Lumetti 5433b8ca49 Add example of SimulationInput usage 2021-05-06 23:07:46 +02:00
Enrico Lumetti bd2abeae3b Add properties() and methods() calls 2021-05-06 23:03:07 +02:00
4 changed files with 55 additions and 2 deletions

9
LICENSE Normal file
View File

@ -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.

View File

@ -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];

BIN
simulink/rc_circuit.slx Normal file

Binary file not shown.

View File

@ -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);