-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hendri54
committed
Jan 5, 2017
1 parent
8023c46
commit e2b350e
Showing
103 changed files
with
15,651 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
classdef MatlabEditor < handle | ||
|
||
properties | ||
% File for saved state | ||
stateFileName char | ||
end | ||
|
||
methods | ||
%% Constructor | ||
function meS = MatlabEditor | ||
lhS = const_lh; | ||
meS.stateFileName = fullfile(lhS.dirS.sharedDirV{1}, 'editor_state.mat'); | ||
end | ||
|
||
|
||
%% Close all open files +++++ | ||
|
||
|
||
%% Generate object with editor state | ||
function sS = get_state(meS) | ||
sS = configLH.MatlabEditorState; | ||
end | ||
|
||
|
||
%% Save editor state | ||
function save_state(meS, fileName) | ||
sS = configLH.MatlabEditorState; | ||
if nargin < 2 | ||
fileName = meS.stateFileName; | ||
end | ||
save(fileName, 'sS'); | ||
end | ||
|
||
|
||
%% Load editor state | ||
function sS = load_state(meS, fileName) | ||
if nargin < 2 | ||
fileName = meS.stateFileName; | ||
end | ||
sS = load(fileName); | ||
sS = sS.sS; | ||
assert(isa(sS, 'configLH.MatlabEditorState')); | ||
end | ||
|
||
|
||
%% Restore state | ||
function restore_state(meS, fileName) | ||
if nargin < 2 | ||
fileName = meS.stateFileName; | ||
end | ||
sS = meS.load_state(fileName); | ||
sS.restore_state; | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
classdef MatlabEditorState < handle | ||
%{ | ||
This is just a container used by MatlabEditor. | ||
Save and load methods are there | ||
%} | ||
|
||
properties | ||
% Paths of open files | ||
openFileV cell | ||
% Line number for each file | ||
lineNumberV double | ||
end | ||
|
||
methods | ||
%% Constructor | ||
function sS = MatlabEditorState | ||
sS.get_state; | ||
end | ||
|
||
|
||
%% Get state | ||
function get_state(sS) | ||
X = matlab.desktop.editor.getAll; | ||
n = length(X); | ||
|
||
if n > 0 | ||
sS.openFileV = cell(n, 1); | ||
sS.lineNumberV = ones(n, 1); | ||
for i1 = 1 : n | ||
sS.openFileV{i1} = X(i1).Filename; | ||
sS.lineNumberV(i1) = X(i1).Selection(1); | ||
end | ||
|
||
else | ||
sS.openFileV = []; | ||
sS.lineNumberV = []; | ||
end | ||
end | ||
|
||
|
||
%% Restore state | ||
function restore_state(sS) | ||
% Open files | ||
n = length(sS.openFileV); | ||
if n > 0 | ||
for i1 = 1 : n | ||
try | ||
edit(sS.openFileV{i1}); | ||
%matlab.desktop.editor.openAndGoToLine(sS.openFileV{i1}, sS.lineNumberV(i1)) | ||
matlab.desktop.editor.openDocument(sS.openFileV{i1}); | ||
activeDoc = matlab.desktop.editor.getActive; | ||
activeDoc.goToPositionInLine(sS.lineNumberV(i1), 1); | ||
catch | ||
fprintf('Cannot open file %s \n', sS.openFileV{i1}); | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function MatlabEditorStateTest | ||
|
||
sS = configLH.MatlabEditorState; | ||
|
||
sS.restore_state; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function MatlabEditorTest | ||
|
||
lhS = const_lh; | ||
fileName = fullfile(lhS.dirS.testFileDir, 'editor_state'); | ||
|
||
meS = configLH.MatlabEditor; | ||
|
||
sS = meS.get_state; | ||
|
||
meS.save_state(fileName); | ||
s2S = meS.load_state(fileName); | ||
assert(isequal(sS, s2S)); | ||
|
||
meS.restore_state(fileName); | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function quit_save(projectSuffix) | ||
% Quit matlab after saving project state | ||
%{ | ||
Restore state with `project_start` | ||
%} | ||
|
||
assert(nargin == 1); | ||
|
||
% Retrieve project info | ||
plS = ProjectListLH; | ||
pS = plS.retrieve_suffix(projectSuffix); | ||
assert(~isempty(pS)); | ||
|
||
% Save project state | ||
meS = configLH.MatlabEditor; | ||
assert(~isempty(pS.stateFileStr)); | ||
meS.save_state(pS.stateFileStr); | ||
|
||
% Quit matlab | ||
quit; | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
% Bounded grid, calibrated from bounded parameters | ||
%{ | ||
Example: | ||
A model with a capital grid between kMin and kMax | ||
Calibrate the grid points | ||
Calibrated parameters are | ||
k1Ratio = (k1 - kMin) / (kMax - kMin) | ||
in [0, 1) | ||
dkV(1 : (n-1)) | ||
dkV(j) = (k(j+1) - k(j)) / (kMax - k(j)) | ||
in (0, 1) | ||
When calling this, bound all inputs to ensure that grid points do not become identical | ||
%} | ||
classdef GridBounded | ||
|
||
properties | ||
% No of grid points | ||
n double | ||
% Bounds | ||
xMin double | ||
xMax double | ||
% % Minimum gap between grid points (optional) | ||
% minGap double = 1e-8; | ||
end | ||
|
||
|
||
methods | ||
%% Constructor | ||
function gS = GridBounded(n, xMin, xMax) | ||
gS.n = n; | ||
gS.xMin = xMin; | ||
gS.xMax = xMax; | ||
|
||
gS.validate; | ||
end | ||
|
||
|
||
%% Validate | ||
function validate(gS) | ||
validateattributes(gS.xMax, {'double'}, {'finite', 'nonnan', 'nonempty', 'real', 'scalar', ... | ||
'>', gS.xMin + 1e-6}) | ||
end | ||
|
||
|
||
%% Make the grid from calibrated parameters | ||
function gridV = make_grid(gS, x1Ratio, dxV) | ||
validateattributes(dxV(:), {'double'}, {'finite', 'nonnan', 'nonempty', 'real', 'positive', '<', 1, ... | ||
'size', [gS.n - 1, 1]}) | ||
validateattributes(x1Ratio, {'double'}, {'finite', 'nonnan', 'nonempty', 'real', 'scalar', '>=', gS.xMin, ... | ||
'<', 1 - 1e-6}) | ||
|
||
gridV = zeros(gS.n, 1); | ||
gridV(1) = gS.xMin + x1Ratio .* (gS.xMax - gS.xMin); | ||
for ig = 1 : (gS.n - 1) | ||
gridV(ig + 1) = gridV(ig) + dxV(ig) .* (gS.xMax - gridV(ig)); | ||
end | ||
|
||
validateattributes(gridV, {'double'}, {'finite', 'nonnan', 'nonempty', 'real', 'increasing', ... | ||
'>=', gS.xMin, '<=', gS.xMax, 'size', [gS.n, 1]}) | ||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function GridBoundedTest | ||
|
||
n = 9; | ||
xMin = -0.9; | ||
xMax = 0.3; | ||
|
||
gS = econLH.GridBounded(n, xMin, xMax); | ||
|
||
rng(904); | ||
x1Ratio = rand(1); | ||
dxV = rand(n-1, 1); | ||
gridV = gS.make_grid(x1Ratio, dxV) | ||
|
||
%keyboard; | ||
|
||
end |
Oops, something went wrong.