Lab changes

This commit is contained in:
Silas Labor Zizou
2024-10-10 11:07:59 +02:00
parent 285fca45eb
commit 6b0f9de118
21 changed files with 901 additions and 100 deletions

View File

@@ -0,0 +1,51 @@
classdef Parameter2 < handle
% PARAMETER2: Represents a physical parameter with mappings between values and indices
properties
name
values
length
physToIndexMap % Rename this from 'getPhysForIndex'
indexToPhysMap % Rename this from 'getIndexForPhys'
end
methods
function obj = Parameter2(name, values)
% Constructor to initialize the Parameter2 object
obj.name = name;
obj.values = values;
obj.length = numel(values);
% Initialize the mappings
obj.physToIndexMap = containers.Map('KeyType', 'double', 'ValueType', 'any');
obj.indexToPhysMap = containers.Map('KeyType', 'double', 'ValueType', 'any');
obj = obj.buildMappings();
end
function obj = buildMappings(obj)
% Build mappings between physical values and indices
for idx = 1:obj.length
obj.indexToPhysMap(idx) = obj.values(idx);
obj.physToIndexMap(obj.values(idx)) = idx;
end
end
function physVal = getPhysForIndex(obj, idx)
% Return the physical value corresponding to the index
if isKey(obj.indexToPhysMap, idx)
physVal = obj.indexToPhysMap(idx);
else
error('Index out of range for parameter %s', obj.name);
end
end
function idx = getIndexByPhys(obj, physVal)
% Return the index corresponding to the physical value
if isKey(obj.physToIndexMap, physVal)
idx = obj.physToIndexMap(physVal);
else
error('Physical value %g not found in parameter %s', physVal, obj.name);
end
end
end
end