Commit 8291393f authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete & Symbolic: bugfixes because of string inputs in plot +...

quantity.Discrete & Symbolic: bugfixes because of string inputs in plot + Symbolic.subs + Symbolic.gridName2variable
parent 1aa3a551
......@@ -1194,47 +1194,47 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
function myLabel = labelHelper(gridNumber)
if ~isempty(obj(rowIdx, columnIdx, figureIdx).gridName)
myLabel = ['$$', greek2tex(obj(rowIdx, columnIdx, figureIdx).gridName{gridNumber}), '$$'];
myLabel = "$$" + greek2tex(obj(rowIdx, columnIdx, figureIdx).gridName{gridNumber}) + "$$";
else
myLabel = '';
myLabel = "";
end
end % labelHelper()
function myTitle = titleHelper()
if numel(obj) <= 1 || ~p.Results.titleWithIndex
myTitle = ['$${', greek2tex(obj(rowIdx, columnIdx, figureIdx).name), '}$$'];
myTitle = "$${" + greek2tex(obj(rowIdx, columnIdx, figureIdx).name) + "}$$";
elseif ndims(obj) <= 2
myTitle = ['$$[{', greek2tex(obj(rowIdx, columnIdx, figureIdx).name), ...
']}_{', num2str(rowIdx), num2str(columnIdx), '}$$'];
myTitle = "$$[{" + greek2tex(obj(rowIdx, columnIdx, figureIdx).name) ...
+ "]}_{" + num2str(rowIdx) + num2str(columnIdx) + "}$$";
else
myTitle = ['$${[', greek2tex(obj(rowIdx, columnIdx, figureIdx).name), ...
']}_{', num2str(rowIdx), num2str(columnIdx), num2str(figureIdx), '}$$'];
myTitle = "$${[" + greek2tex(obj(rowIdx, columnIdx, figureIdx).name) ...
+ "]}_{" + num2str(rowIdx) + num2str(columnIdx) + num2str(figureIdx) + "}$$";
end
end % titleHelper()
function myText = greek2tex(myText)
if ~contains(myText, '\')
myText = strrep(myText, 'Lambda', '\Lambda');
myText = strrep(myText, 'lambda', '\lambda');
myText = strrep(myText, 'Zeta', '\Zeta');
myText = strrep(myText, 'zeta', '\zeta');
myText = strrep(myText, 'Gamma', '\Gamma');
myText = strrep(myText, 'gamma', '\gamma');
myText = strrep(myText, 'psi', '\psi');
myText = strrep(myText, 'phi', '\phi');
myText = strrep(myText, 'Psi', '\Psi');
myText = strrep(myText, 'Phi', '\Phi');
myText = strrep(myText, 'Delta', '\Delta');
myText = strrep(myText, 'delta', '\delta');
if ~contains(myText, '\zeta') && ~contains(myText, '\Zeta')
myText = strrep(myText, 'eta', '\eta');
if ~contains(myText, "\")
myText = strrep(myText, "Lambda", "\Lambda");
myText = strrep(myText, "lambda", "\lambda");
myText = strrep(myText, "Zeta", "\Zeta");
myText = strrep(myText, "zeta", "\zeta");
myText = strrep(myText, "Gamma", "\Gamma");
myText = strrep(myText, "gamma", "\gamma");
myText = strrep(myText, "psi", "\psi");
myText = strrep(myText, "phi", "\phi");
myText = strrep(myText, "Psi", "\Psi");
myText = strrep(myText, "Phi", "\Phi");
myText = strrep(myText, "Delta", "\Delta");
myText = strrep(myText, "delta", "\delta");
if ~contains(myText, "\zeta") && ~contains(myText, "\Zeta")
myText = strrep(myText, "eta", "\eta");
end
myText = strrep(myText, 'pi', '\pi');
myText = strrep(myText, 'Pi', '\Pi');
myText = strrep(myText, "pi", "\pi");
myText = strrep(myText, "Pi", "\Pi");
end
end % greek2tex()
end % plot()
function s = nameValuePair(obj, varargin)
assert(numel(obj) == 1, 'nameValuePair must NOT be called for an array object');
assert(numel(obj) == 1, "nameValuePair must NOT be called for an array object");
s = struct(obj);
if ~isempty(varargin)
s = rmfield(s, varargin{:});
......@@ -1243,7 +1243,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end % nameValuePair()
function s = struct(obj, varargin)
if (nargin == 1) && isa(obj, 'quantity.Discrete')
if (nargin == 1) && isa(obj, "quantity.Discrete")
properties = fieldnames(obj);
si = num2cell( size(obj) );
s(si{:}) = struct();
......
......@@ -307,6 +307,13 @@ classdef Symbolic < quantity.Function
return
else
values = misc.ensureIsCell(values);
for it = 1 : numel(values)
% for later strcmp usage, values must be a cell-array with only
% numeric or char elements.
if isstring(values{it})
values{it} = char(values{it});
end
end % for it = 1 : numel(values)
end
isNumericValue = cellfun(@isnumeric, values);
......@@ -355,13 +362,13 @@ classdef Symbolic < quantity.Function
newGrid = cell(1, numel(newGridName));
charValues = cell(0);
for it = 1 : numel(values)
if ischar(values{it})
charValues{end+1} = values{it};
if isstring(values{it}) || ischar(values{it})
charValues{end+1} = char(values{it});
end
end
for it = 1 : numel(newGridName)
if ~isempty(charValues) && any(contains(charValues, newGridName{it}))
newGrid{it} = obj.gridOf(gridName( strcmp(values, newGridName{it}) ));
newGrid{it} = obj.gridOf(gridName( strcmp(newGridName{it}, values) ));
else
newGrid{it} = obj.gridOf(newGridName{it});
end
......@@ -543,12 +550,11 @@ classdef Symbolic < quantity.Function
% in the order specified by thisGridName. If thisGridName is a char, then
% only one variable is returned. If thisGridName is a cell-array, then a
% cell array of variables is returned.
if ischar(thisGridName)
if isstring(thisGridName) || ischar(thisGridName)
assert(any(strcmp(obj(1).gridName, thisGridName)), ...
['The gridName ', thisGridName, ' is not a gridName of this Quantity']);
variableNames = arrayfun(@(v) char(v), obj(1).variable, 'UniformOutput', false);
selectVariable = strcmp(variableNames, thisGridName);
assert(sum(selectVariable) == 1);
selectVariable = strcmp(string(obj(1).variable), thisGridName);
assert(any(selectVariable));
thisVariable = obj(1).variable(selectVariable);
elseif iscell(thisGridName)
......
......@@ -766,6 +766,12 @@ solution = f.solveAlgebraic([1, 1], f(1).gridName{1});
testCase.verifyEqual(solution, 0.5);
end
function testSubs2(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
Id = quantity.Symbolic(eye(2), "domain", z);
tc.verifyEqual(Id.on(), Id.subs("z", "zeta").on(), 'AbsTol', 10*eps);
end % testSubs2()
function testSubs(testCase)
%%
% init
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment