text:
classdef SO3FunComposition < SO3Fun
% a class representing a function on the rotation group as sum of other
% SO3Funs. Therefore the summands possibly are different subclasses of
% SO3Fun (e.g. SO3FunRBF, SO3FunCBF, SO3FunBingham, ...), which are stored as components.
%
% Syntax
%   SO3F = SO3FunComposition(F1,F2,F3)
%
% Input
%  F1,F2,F3 - @SO3Fun
%
% Output
%  SO3F - @SO3FunComposition
%
% Example
%
%   F1 = SO3FunCBF.example;
%   F2 = SO3FunRBF.example;
%   F2.CS = F1.CS;
%   SO3F = F1+F2
%
%

properties
  components = {}
end

properties (Dependent = true)
  bandwidth % harmonic degree
  % TODO: antipodal wird nicht gesetzt/verwendet
  antipodal
  SLeft
  SRight
  weights
end

methods
  function SO3F = SO3FunComposition(varargin)

    % construct cell array of all components
    components =[];
    isCompo = cellfun(@(x) isa(x,'SO3FunComposition'),varargin);
    if any(isCompo)
      isCompoComponents = cellfun(@(x) x.components,varargin(isCompo),'UniformOutput',false);
      components = [isCompoComponents{:}];
      varargin(isCompo) = [];
    end
    components = [components,varargin];

    % check for equal sizes
    if any(cellfun(@numel,components)~=1)
      error('The components have to be equalsized.')
    end

    % constant component
    c = 0;
    isConstant = cellfun(@isnumeric,components);
    if any(isConstant)
      c = c + sum([components{isConstant}]);
    end
    isUniform = cellfun(@(x) isa(x,'SO3FunRBF') && x.c0~=0 && isempty(x.weights),components);
    if any(isUniform)
      c = c + sum(cellfun(@(x) x.c0, components(isUniform)));
    end
    isRBFandUniform = cellfun(@(x) isa(x,'SO3FunRBF') && x.c0~=0 && ~isempty(x.weights),components);
    for ind = find(isRBFandUniform)
      c = c + components{ind}.c0;
      components{ind}.c0 = 0;
    end

    % fourier component
    Harm = 0;
    isHarmonic = cellfun(@(x) isa(x,'SO3FunHarmonic'),components);
    if any(isHarmonic)
      Harm = sum([components{isHarmonic}],2);
    end

    % write constant and fourier components
    SO3F.components = {};
    if c~=0
      % choose Symmetry (properties of ensureCompatibleSymmetries, i.e. symmetries have to be the same)
      if any(~isConstant & ~isUniform)
        CS = components{find(~isConstant & ~isUniform,1)}.CS;
        SS = components{find(~isConstant & ~isUniform,1)}.SS;
      else
        CS = crystalSymmetry;
        SS = specimenSymmetry;
      end
      SO3F.components = {c * uniformODF(CS,SS)};
    end
    if any(isHarmonic)
      SO3F.components = [SO3F.components,{Harm}];
    end

    % remaining components
    isRemaining = ~isConstant & ~isHarmonic & ~isUniform;
    if any(isRemaining)
      SO3F.components = [SO3F.components,components(isRemaining)];
    end

    % ensureCompatibleSymmetries
    if var(cellfun(@(x) x.CS.id ,SO3F.components)) ~=0 || ...
          var(cellfun(@(x) x.SS.id ,SO3F.components)) ~= 0
      error('Calculations with @SO3Fun''s are not supported if the symmetries are not compatible.')
    end

  end

  function f = eval(SO3F,rot,varargin)

%     if isa(rot,'orientation')
%       ensureCompatibleSymmetries(SO3F,rot)
%     end

    f = 0;
    for k = 1:length(SO3F.components)
      f = f + eval(SO3F.components{k},rot,varargin{:});
    end

    if isalmostreal(f)
      f = real(f);
    end

  end

  function w = get.weights(S3F)
    w = cellfun(@(x) mean(x,'all'), S3F.components);
  end

  function out = get.antipodal(S3F)
    out = all(cellfun(@(x) x.antipodal ,S3F.components));
  end

  function out = get.bandwidth(S3F)
    out =  max(cellfun(@(x) x.bandwidth,S3F.components));
  end

  function out = get.SLeft(S3F)
    out = S3F.components{1}.SLeft;
  end

  function out = get.SRight(S3F)
    out = S3F.components{1}.SRight;
  end

  function SO3F = set.SRight(SO3F,CS)
   for k=1:length(SO3F.components)
     SO3F.components{k}.SRight = CS;
   end
  end

  function SO3F = set.SLeft(SO3F,SS)
    for k=1:length(SO3F.components)
     SO3F.components{k}.SLeft = SS;
   end
  end

end

methods (Static = true)

  SO3F = example(varargin)

end

end

author: mtex-toolbox

repo: mtex

save_path: github-repos/MATLAB/mtex-toolbox-mtex


text:
function varargout = lvd_viewSettingsGUI(varargin)
    % LVD_VIEWSETTINGSGUI MATLAB code for lvd_viewSettingsGUI.fig
    %      LVD_VIEWSETTINGSGUI, by itself, creates a new LVD_VIEWSETTINGSGUI or raises the existing
    %      singleton*.
    %
    %      H = LVD_VIEWSETTINGSGUI returns the handle to a new LVD_VIEWSETTINGSGUI or the handle to
    %      the existing singleton*.
    %
    %      LVD_VIEWSETTINGSGUI('CALLBACK',hObject,eventData,handles,...) calls the local
    %      function named CALLBACK in LVD_VIEWSETTINGSGUI.M with the given input arguments.
    %
    %      LVD_VIEWSETTINGSGUI('Property','Value',...) creates a new LVD_VIEWSETTINGSGUI or raises the
    %      existing singleton*.  Starting from the left, property value pairs are
    %      applied to the GUI before lvd_viewSettingsGUI_OpeningFcn gets called.  An
    %      unrecognized property name or invalid value makes property application
    %      stop.  All inputs are passed to lvd_viewSettingsGUI_OpeningFcn via varargin.
    %
    %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
    %      instance to run (singleton)".
    %
    % See also: GUIDE, GUIDATA, GUIHANDLES

    % Edit the above text to modify the response to help lvd_viewSettingsGUI

    % Last Modified by GUIDE v2.5 18-Feb-2021 10:06:40

    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name',       mfilename, ...
        'gui_Singleton',  gui_Singleton, ...
        'gui_OpeningFcn', @lvd_viewSettingsGUI_OpeningFcn, ...
        'gui_OutputFcn',  @lvd_viewSettingsGUI_OutputFcn, ...
        'gui_LayoutFcn',  [] , ...
        'gui_Callback',   []);
    if nargin && ischar(varargin{1})
        gui_State.gui_Callback = str2func(varargin{1});
    end

    if nargout
        [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    else
        gui_mainfcn(gui_State, varargin{:});
    end
    % End initialization code - DO NOT EDIT

    % --- Executes just before lvd_viewSettingsGUI is made visible.
function lvd_viewSettingsGUI_OpeningFcn(hObject, eventdata, handles, varargin)
    % This function has no output args, see OutputFcn.
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    % varargin   command line arguments to lvd_viewSettingsGUI (see VARARGIN)

    % Choose default command line output for lvd_viewSettingsGUI
    handles.output = hObject;

    viewSettings = varargin{1};
    setappdata(hObject,'viewSettings',viewSettings);

    handles = populateGUI(viewSettings, handles);

    % Update handles structure
    guidata(hObject, handles);

    disp(double(handles.moveViewProfileUpButton.String));

    % UIWAIT makes lvd_viewSettingsGUI wait for user response (see UIRESUME)
    uiwait(handles.lvd_viewSettingsGUI);

function handles = populateGUI(viewSettings, handles)
    handles.viewProfilesListbox.String = viewSettings.getListboxStr();
    handles.viewProfilesListbox.Value = viewSettings.getIndOfSelectedProfile();

    celBodyData = viewSettings.lvdData.celBodyData;
    populateBodiesCombo(celBodyData, handles.bodiesToPlotListbox);

    grdObjSet = viewSettings.lvdData.groundObjs;
    handles.grdObjsListbox.String = grdObjSet.getListboxStr();

    geometry = viewSettings.lvdData.geometry;
	[~, plotPointsListBoxStr] = geometry.points.getPlottablePoints();
    handles.pointsToPlotListbox.String = plotPointsListBoxStr;
    handles.vectorsToPlotListbox.String = geometry.vectors.getListboxStr();
    handles.refFramessToPlotListbox.String = geometry.refFrames.getListboxStr();
    handles.anglesToPlotListbox.String = geometry.angles.getListboxStr();
    handles.planesToPlotListbox.String = geometry.planes.getListboxStr();

    profile = getSelectedProfile(handles);
    updateGuiForProfile(profile, handles);
    setDeleteButtonEnable(handles);

function updateGuiForProfile(profile, handles)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    celBodyData = viewSettings.lvdData.celBodyData;

    handles.nameText.String = profile.name;
    handles.profileDesc.String = profile.desc;
    handles.setAsActiveProfileCheckbox.Value = viewSettings.isProfileActive(profile);

    handles.showSoICheckbox.Value = profile.showSoIRadius;
    handles.showFixedFrameGridCheckbox.Value = profile.showLongLatAnnotations;

    handles.axesBackgroundColorCombo.String = ColorSpecEnum.getListboxStr();
    handles.axesBackgroundColorCombo.Value = ColorSpecEnum.getIndForName(profile.backgroundColor.name);

    handles.majorGridLinesColorCombo.String = ColorSpecEnum.getListboxStr();
    handles.majorGridLinesColorCombo.Value = ColorSpecEnum.getIndForName(profile.majorGridColor.name);

    handles.gridTypeCombo.String = ViewGridTypeEnum.getListBoxStr();
    handles.gridTypeCombo.Value = ViewGridTypeEnum.getIndForName(profile.gridType.name);

    handles.minorGridLinesColorCombo.String = ColorSpecEnum.getListboxStr();
    handles.minorGridLinesColorCombo.Value = ColorSpecEnum.getIndForName(profile.minorGridColor.name);

    handles.gridAlphaText.String = fullAccNum2Str(100*profile.gridTransparency);

    handles.evtsPlottingStyleCombo.String = ViewEventsTypeEnum.getListBoxStr();
    handles.evtsPlottingStyleCombo.Value = ViewEventsTypeEnum.getIndForName(profile.trajEvtsViewType.name);

    handles.trajViewFrameCombo.String = ReferenceFrameEnum.getListBoxStr();
    handles.trajViewFrameCombo.Value = ReferenceFrameEnum.getIndForName(profile.frame.typeEnum.name);
    handles.setFrameOptionsButton.TooltipString = sprintf('Current Frame: %s', profile.frame.getNameStr());

    [~, sortedBodyInfo] = ma_getSortedBodyNames(celBodyData);

    indsToSel = [];
    for(i=1:length(profile.bodiesToPlot))
        tf = cellfun(@(c) c == profile.bodiesToPlot(i), sortedBodyInfo);
        indsToSel(end+1) = find(tf,1,'first'); %#ok<AGROW>
    end
    handles.bodiesToPlotListbox.Value = indsToSel;

    handles.bodyPlottingStyleCombo.String = ViewProfileBodyPlottingStyle.getListBoxStr();
    handles.bodyPlottingStyleCombo.Value = ViewProfileBodyPlottingStyle.getIndForName(profile.bodyPlotStyle.name);

    handles.displayXAxisCheckbox.Value = double(profile.dispXAxis);
    handles.displayYAxisCheckbox.Value = double(profile.dispYAxis);
    handles.displayZAxisCheckbox.Value = double(profile.dispZAxis);

    handles.showThrustVectorsCheckbox.Value = double(profile.showThrustVectors);

    handles.thrustVectColorCombo.String = ColorSpecEnum.getListboxStr();
    handles.thrustVectColorCombo.Value = ColorSpecEnum.getIndForName(profile.thrustVectColor.name);

    handles.thrustVectLineStyleCombo.String = LineSpecEnum.getListboxStr();
    handles.thrustVectLineStyleCombo.Value = LineSpecEnum.getIndForName(profile.thrustVectLineType.name);

    handles.thrustVectScaleText.String = fullAccNum2Str(profile.thrustVectScale);
    handles.thrustVectIncrText.String = fullAccNum2Str(profile.thrustVectEntryIncr);

    handles.showSunLightingCheckbox.Value = double(profile.showLighting);
    handles.showSunVectorCheckbox.Value = double(profile.showSunVect);

    handles.showScBodyAxesCheckbox.Value = double(profile.showScBodyAxes);
    handles.scBodyAxesScaleText.String = fullAccNum2Str(profile.scBodyAxesScale);

    grdObjSet = viewSettings.lvdData.groundObjs;
    handles.grdObjsListbox.Value = grdObjSet.getIndsForGroundObjs(profile.groundObjsToPlot);
    handles.showGrdObjTrksCheckbox.Value = double(profile.showGndTracks);
    handles.showLoSToScCheckbox.Value = double(profile.showGrdObjLoS);

    handles.rendererCombo.String = FigureRendererEnum.getListboxStr();
    handles.rendererCombo.Value = FigureRendererEnum.getIndForName(profile.renderer.name);

    handles.meshEdgeAlphaText.String = fullAccNum2Str(100*profile.meshEdgeAlpha);

    handles.updateViewAxesCheckbox.Value = double(profile.updateViewAxesLimits);

    handles.showCbAtmo.Value = double(profile.showAtmosphere);

    geometry = viewSettings.lvdData.geometry;
    [plotPoints, ~] = geometry.points.getPlottablePoints();
    handles.pointsToPlotListbox.Value = find(ismember(plotPoints, profile.pointsToPlot));
    handles.vectorsToPlotListbox.Value = geometry.vectors.getIndsForVectors(profile.vectorsToPlot);
    handles.refFramessToPlotListbox.Value = geometry.refFrames.getIndsForRefFrames(profile.refFramesToPlot);
    handles.anglesToPlotListbox.Value = geometry.angles.getIndsForAngles(profile.anglesToPlot);
    handles.planesToPlotListbox.Value = geometry.planes.getIndsForPlanes(profile.planesToPlot);

    setDeleteButtonEnable(handles);

function profile = getSelectedProfile(handles)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');

    ind = handles.viewProfilesListbox.Value;
    profile = viewSettings.getProfileAtInd(ind);

function setDeleteButtonEnable(handles)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    numProfiles = viewSettings.getNumProfiles();

    if(numProfiles > 1)
        handles.removeViewProfileButton.Enable = 'on';
    else
        handles.removeViewProfileButton.Enable = 'off';
    end

    % --- Outputs from this function are returned to the command line.
function varargout = lvd_viewSettingsGUI_OutputFcn(hObject, eventdata, handles)
    % varargout  cell array for returning output args (see VARARGOUT);
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Get default command line output from handles structure
    if(isempty(handles))
        varargout{1} = false;
    else
        varargout{1} = true;
        close(handles.lvd_viewSettingsGUI);
    end

    % --- Executes on selection change in viewProfilesListbox.
function viewProfilesListbox_Callback(hObject, eventdata, handles)
    % hObject    handle to viewProfilesListbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns viewProfilesListbox contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from viewProfilesListbox
    profile = getSelectedProfile(handles);
    updateGuiForProfile(profile, handles);

    % --- Executes during object creation, after setting all properties.
function viewProfilesListbox_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to viewProfilesListbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: listbox controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on button press in addViewProfileButton.
function addViewProfileButton_Callback(hObject, eventdata, handles)
    % hObject    handle to addViewProfileButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    newProfile = LaunchVehicleViewProfile();
%     newProfile.frame = BodyCenteredInertialFrame(viewSettings.lvdData.initialState.centralBody, viewSettings.lvdData.celBodyData);
    newProfile.frame = viewSettings.lvdData.initialState.centralBody.getBodyCenteredInertialFrame();
    viewSettings.addViewProfile(newProfile);

    handles.viewProfilesListbox.String = viewSettings.getListboxStr();

    handles.viewProfilesListbox.Value = viewSettings.getNumProfiles();
    updateGuiForProfile(newProfile, handles);
    setDeleteButtonEnable(handles);

    % --- Executes on button press in removeViewProfileButton.
function removeViewProfileButton_Callback(hObject, eventdata, handles)
    % hObject    handle to removeViewProfileButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');

    profile = getSelectedProfile(handles);
    isActiveProfile = viewSettings.isProfileActive(profile);
    viewSettings.removeViewProfile(profile);
    numProfiles = viewSettings.getNumProfiles();

    handles.viewProfilesListbox.String = viewSettings.getListboxStr();

    if(handles.viewProfilesListbox.Value > numProfiles)
        handles.viewProfilesListbox.Value = numProfiles;
    end

    profile = getSelectedProfile(handles);
    if(isActiveProfile)
        viewSettings.setProfileAsActive(profile);
        handles.viewProfilesListbox.String = viewSettings.getListboxStr();
    end

    updateGuiForProfile(profile, handles);
    setDeleteButtonEnable(handles);

    % --- Executes on button press in moveViewProfileDownButton.
function moveViewProfileDownButton_Callback(hObject, eventdata, handles)
    % hObject    handle to moveViewProfileDownButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');

    profileNum = get(handles.viewProfilesListbox,'Value');
    viewSettings.moveProfileAtIndexDown(profileNum);

    if(profileNum < viewSettings.getNumProfiles())
        set(handles.viewProfilesListbox,'Value',profileNum+1);
    end

    handles.viewProfilesListbox.String = viewSettings.getListboxStr();

    % --- Executes on button press in moveViewProfileUpButton.
function moveViewProfileUpButton_Callback(hObject, eventdata, handles)
    % hObject    handle to moveViewProfileUpButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');

    profileNum = get(handles.viewProfilesListbox,'Value');
    viewSettings.moveProfileAtIndexUp(profileNum);

    if(profileNum > 1)
        set(handles.viewProfilesListbox,'Value',profileNum-1);
    end

    handles.viewProfilesListbox.String = viewSettings.getListboxStr();

function nameText_Callback(hObject, eventdata, handles)
    % hObject    handle to nameText (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: get(hObject,'String') returns contents of nameText as text
    %        str2double(get(hObject,'String')) returns contents of nameText as a double
    profile = getSelectedProfile(handles);
    profile.name = get(hObject,'String');

    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    handles.viewProfilesListbox.String = viewSettings.getListboxStr();

    % --- Executes during object creation, after setting all properties.
function nameText_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to nameText (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: edit controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

function profileDesc_Callback(hObject, eventdata, handles)
    % hObject    handle to profileDesc (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: get(hObject,'String') returns contents of profileDesc as text
    %        str2double(get(hObject,'String')) returns contents of profileDesc as a double
    profile = getSelectedProfile(handles);
    profile.desc = get(hObject,'String');

    % --- Executes during object creation, after setting all properties.
function profileDesc_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to profileDesc (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: edit controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on selection change in axesBackgroundColorCombo.
function axesBackgroundColorCombo_Callback(hObject, eventdata, handles)
    % hObject    handle to axesBackgroundColorCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns axesBackgroundColorCombo contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from axesBackgroundColorCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.backgroundColor = ColorSpecEnum.getEnumForListboxStr(str);

    % --- Executes during object creation, after setting all properties.
function axesBackgroundColorCombo_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to axesBackgroundColorCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: popupmenu controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on selection change in majorGridLinesColorCombo.
function majorGridLinesColorCombo_Callback(hObject, eventdata, handles)
    % hObject    handle to majorGridLinesColorCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns majorGridLinesColorCombo contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from majorGridLinesColorCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.majorGridColor = ColorSpecEnum.getEnumForListboxStr(str);

    % --- Executes during object creation, after setting all properties.
function majorGridLinesColorCombo_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to majorGridLinesColorCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: popupmenu controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on selection change in minorGridLinesColorCombo.
function minorGridLinesColorCombo_Callback(hObject, eventdata, handles)
    % hObject    handle to minorGridLinesColorCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns minorGridLinesColorCombo contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from minorGridLinesColorCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.minorGridColor = ColorSpecEnum.getEnumForListboxStr(str);

    % --- Executes during object creation, after setting all properties.
function minorGridLinesColorCombo_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to minorGridLinesColorCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: popupmenu controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on selection change in gridTypeCombo.
function gridTypeCombo_Callback(hObject, eventdata, handles)
    % hObject    handle to gridTypeCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns gridTypeCombo contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from gridTypeCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.gridType = ViewGridTypeEnum.getEnumForListboxStr(str);

    % --- Executes during object creation, after setting all properties.
function gridTypeCombo_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to gridTypeCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: popupmenu controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

function gridAlphaText_Callback(hObject, eventdata, handles)
    % hObject    handle to gridAlphaText (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: get(hObject,'String') returns contents of gridAlphaText as text
    %        str2double(get(hObject,'String')) returns contents of gridAlphaText as a double
    newInput = get(hObject,'String');
    newInput = attemptStrEval(newInput);
    set(hObject,'String', newInput);

    profile = getSelectedProfile(handles);

    errMsg = {};

    alpha = str2double(get(hObject,'String'));
    enteredStr = get(hObject,'String');
    numberName = 'Grid Transparency';
    lb = 0;
    ub = 100;
    isInt = false;
    errMsg = validateNumber(alpha, numberName, lb, ub, isInt, errMsg, enteredStr);

    if(isempty(errMsg))
        profile.gridTransparency = alpha/100;
    else
        hObject.String = fullAccNum2Str(profile.gridTransparency);

        msgbox(errMsg,'Invalid Grid Transparency Value','error');
    end

    % --- Executes during object creation, after setting all properties.
function gridAlphaText_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to gridAlphaText (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: edit controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on selection change in evtsPlottingStyleCombo.
function evtsPlottingStyleCombo_Callback(hObject, eventdata, handles)
    % hObject    handle to evtsPlottingStyleCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns evtsPlottingStyleCombo contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from evtsPlottingStyleCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.trajEvtsViewType = ViewEventsTypeEnum.getEnumForListboxStr(str);

    % --- Executes during object creation, after setting all properties.
function evtsPlottingStyleCombo_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to evtsPlottingStyleCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: popupmenu controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on selection change in trajViewFrameCombo.
function trajViewFrameCombo_Callback(hObject, eventdata, handles)
    % hObject    handle to trajViewFrameCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns trajViewFrameCombo contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from trajViewFrameCombo
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    lvdData = viewSettings.lvdData;
    celBodyData = lvdData.celBodyData;

    profile = getSelectedProfile(handles);
    bodyInfo = profile.frame.getOriginBody();

    contents = cellstr(get(handles.trajViewFrameCombo,'String'));
    selFrameType = contents{get(handles.trajViewFrameCombo,'Value')};
    refFrameEnum = ReferenceFrameEnum.getEnumForListboxStr(selFrameType);

    switch refFrameEnum
        case ReferenceFrameEnum.BodyCenteredInertial
            newFrame = bodyInfo.getBodyCenteredInertialFrame();

        case ReferenceFrameEnum.BodyFixedRotating
            newFrame = bodyInfo.getBodyFixedFrame();

        case ReferenceFrameEnum.TwoBodyRotating
            if(not(isempty(bodyInfo.childrenBodyInfo)))
                primaryBody = bodyInfo;
                secondaryBody = bodyInfo.childrenBodyInfo(1);
            else
                primaryBody = bodyInfo.getParBodyInfo();
                secondaryBody = bodyInfo;
            end

            originPt = TwoBodyRotatingFrameOriginEnum.Primary;

            newFrame = TwoBodyRotatingFrame(primaryBody, secondaryBody, originPt, celBodyData);

        case ReferenceFrameEnum.UserDefined
            numFrames = lvdData.geometry.refFrames.getNumRefFrames();
            if(numFrames >= 1)
                geometricFrame = AbstractGeometricRefFrame.empty(1,0);
                for(i=1:numFrames)
                    frame = lvdData.geometry.refFrames.getRefFrameAtInd(i);
                    if(frame.isVehDependent() == false)
                        geometricFrame = frame;
                        break;
                    end
                end

                if(not(isempty(geometricFrame)))
                    newFrame = UserDefinedGeometricFrame(geometricFrame, lvdData);
                else
                    newFrame = bodyInfo.getBodyCenteredInertialFrame();

                    warndlg('There are no geometric frames available which are not dependent on vehicle properties.  A body-centered inertial frame will be selected instead.');
                end
            else
                bodyInfo = getSelectedBodyInfo(handles);
                newFrame = bodyInfo.getBodyCenteredInertialFrame();

                warndlg('There are no geometric frames available which are not dependent on vehicle properties.  A body-centered inertial frame will be selected instead.');
            end

        otherwise
            error('Unknown reference frame type: %s', string(refFrameEnum));
    end

    if(not(isempty(newFrame)) && newFrame.typeEnum ~= refFrameEnum)
        refFrameEnum = newFrame.typeEnum;
        handles.trajViewFrameCombo.Value = ReferenceFrameEnum.getIndForName(refFrameEnum.name);
    end

    profile.frame = newFrame;
    handles.setFrameOptionsButton.TooltipString = sprintf('Current Frame: %s', profile.frame.getNameStr());

    % --- Executes during object creation, after setting all properties.
function trajViewFrameCombo_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to trajViewFrameCombo (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: popupmenu controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on button press in showSoICheckbox.
function showSoICheckbox_Callback(hObject, eventdata, handles)
    % hObject    handle to showSoICheckbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hint: get(hObject,'Value') returns toggle state of showSoICheckbox
    profile = getSelectedProfile(handles);
    profile.showSoIRadius = logical(get(hObject,'Value'));

    % --- Executes on button press in showFixedFrameGridCheckbox.
function showFixedFrameGridCheckbox_Callback(hObject, eventdata, handles)
    % hObject    handle to showFixedFrameGridCheckbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hint: get(hObject,'Value') returns toggle state of showFixedFrameGridCheckbox
    profile = getSelectedProfile(handles);
    profile.showLongLatAnnotations = logical(get(hObject,'Value'));

    % --- Executes on button press in saveAndCloseButton.
function saveAndCloseButton_Callback(hObject, eventdata, handles)
    % hObject    handle to saveAndCloseButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    errMsg = {};
    if(isempty(errMsg))
        uiresume(handles.lvd_viewSettingsGUI);
    else
        msgbox(errMsg,'Errors were found while editing plugins.','error');
    end

    % --- Executes on button press in setAsActiveProfileCheckbox.
function setAsActiveProfileCheckbox_Callback(hObject, eventdata, handles)
    % hObject    handle to setAsActiveProfileCheckbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hint: get(hObject,'Value') returns toggle state of setAsActiveProfileCheckbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    profile = getSelectedProfile(handles);

    viewSettings.setProfileAsActive(profile);

    updateGuiForProfile(profile, handles);

    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    handles.viewProfilesListbox.String = viewSettings.getListboxStr();

    % --- Executes on selection change in bodiesToPlotListbox.
function bodiesToPlotListbox_Callback(hObject, eventdata, handles)
    % hObject    handle to bodiesToPlotListbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns bodiesToPlotListbox contents as cell array
    %        contents{get(hObject,'Value')} returns selected item from bodiesToPlotListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    celBodyData = viewSettings.lvdData.celBodyData;
    [~, sortedBodyInfo] = ma_getSortedBodyNames(celBodyData);

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        profile.bodiesToPlot = [sortedBodyInfo{inds}];
    else
        profile.bodiesToPlot = KSPTOT_BodyInfo.empty(1,0);
    end

    % --- Executes during object creation, after setting all properties.
function bodiesToPlotListbox_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to bodiesToPlotListbox (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: listbox controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

    % --- Executes on button press in setFrameOptionsButton.
function setFrameOptionsButton_Callback(hObject, eventdata, handles)
    % hObject    handle to setFrameOptionsButton (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    profile = getSelectedProfile(handles);
    newFrame = profile.frame.editFrameDialogUI(EditReferenceFrameContextEnum.ForView);

    profile.frame = newFrame;
    handles.setFrameOptionsButton.TooltipString = sprintf('Current Frame: %s', profile.frame.getNameStr());

% --- Executes on selection change in bodyPlottingStyleCombo.
function bodyPlottingStyleCombo_Callback(hObject, eventdata, handles)
% hObject    handle to bodyPlottingStyleCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns bodyPlottingStyleCombo contents as cell array
%        contents{get(hObject,'Value')} returns selected item from bodyPlottingStyleCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.bodyPlotStyle = ViewProfileBodyPlottingStyle.getEnumForListboxStr(str);

% --- Executes during object creation, after setting all properties.
function bodyPlottingStyleCombo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bodyPlottingStyleCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in displayXAxisCheckbox.
function displayXAxisCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to displayXAxisCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of displayXAxisCheckbox
    profile = getSelectedProfile(handles);
    profile.dispXAxis = logical(get(hObject,'Value'));

% --- Executes on button press in displayYAxisCheckbox.
function displayYAxisCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to displayYAxisCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of displayYAxisCheckbox
    profile = getSelectedProfile(handles);
    profile.dispYAxis = logical(get(hObject,'Value'));

% --- Executes on button press in displayZAxisCheckbox.
function displayZAxisCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to displayZAxisCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of displayZAxisCheckbox
    profile = getSelectedProfile(handles);
    profile.dispZAxis = logical(get(hObject,'Value'));

% --- Executes on button press in showThrustVectorsCheckbox.
function showThrustVectorsCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to showThrustVectorsCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showThrustVectorsCheckbox
    profile = getSelectedProfile(handles);
    profile.showThrustVectors = logical(get(hObject,'Value'));

% --- Executes on selection change in thrustVectColorCombo.
function thrustVectColorCombo_Callback(hObject, eventdata, handles)
% hObject    handle to thrustVectColorCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns thrustVectColorCombo contents as cell array
%        contents{get(hObject,'Value')} returns selected item from thrustVectColorCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.thrustVectColor = ColorSpecEnum.getEnumForListboxStr(str);

% --- Executes during object creation, after setting all properties.
function thrustVectColorCombo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to thrustVectColorCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in thrustVectLineStyleCombo.
function thrustVectLineStyleCombo_Callback(hObject, eventdata, handles)
% hObject    handle to thrustVectLineStyleCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns thrustVectLineStyleCombo contents as cell array
%        contents{get(hObject,'Value')} returns selected item from thrustVectLineStyleCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.thrustVectLineType = LineSpecEnum.getEnumForListboxStr(str);

% --- Executes during object creation, after setting all properties.
function thrustVectLineStyleCombo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to thrustVectLineStyleCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function thrustVectIncrText_Callback(hObject, eventdata, handles)
% hObject    handle to thrustVectIncrText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of thrustVectIncrText as text
%        str2double(get(hObject,'String')) returns contents of thrustVectIncrText as a double
    newInput = get(hObject,'String');
    newInput = attemptStrEval(newInput);
    set(hObject,'String', newInput);

    profile = getSelectedProfile(handles);

    errMsg = {};

    incr = str2double(get(hObject,'String'));
    enteredStr = get(hObject,'String');
    numberName = 'Thrust Vector Data Point Increment';
    lb = 1;
    ub = Inf;
    isInt = true;
    errMsg = validateNumber(incr, numberName, lb, ub, isInt, errMsg, enteredStr);

    if(isempty(errMsg))
        profile.thrustVectEntryIncr = incr;
    else
        hObject.String = fullAccNum2Str(profile.thrustVectEntryIncr);

        msgbox(errMsg,'Invalid Thrust Vector Data Point Incrememnt','error');
    end

% --- Executes during object creation, after setting all properties.
function thrustVectIncrText_CreateFcn(hObject, eventdata, handles)
% hObject    handle to thrustVectIncrText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function thrustVectScaleText_Callback(hObject, eventdata, handles)
% hObject    handle to thrustVectScaleText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of thrustVectScaleText as text
%        str2double(get(hObject,'String')) returns contents of thrustVectScaleText as a double
    newInput = get(hObject,'String');
    newInput = attemptStrEval(newInput);
    set(hObject,'String', newInput);

    profile = getSelectedProfile(handles);

    errMsg = {};

    scale = str2double(get(hObject,'String'));
    enteredStr = get(hObject,'String');
    numberName = 'Thrust Vector Scale Factor';
    lb = 0;
    ub = Inf;
    isInt = false;
    errMsg = validateNumber(scale, numberName, lb, ub, isInt, errMsg, enteredStr);

    if(isempty(errMsg))
        profile.thrustVectScale = scale;
    else
        hObject.String = fullAccNum2Str(profile.thrustVectScale);

        msgbox(errMsg,'Invalid Thrust Vector Scale Factor Value','error');
    end

% --- Executes during object creation, after setting all properties.
function thrustVectScaleText_CreateFcn(hObject, eventdata, handles)
% hObject    handle to thrustVectScaleText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on key press with focus on lvd_viewSettingsGUI or any of its controls.
function lvd_viewSettingsGUI_WindowKeyPressFcn(hObject, eventdata, handles)
% hObject    handle to lvd_viewSettingsGUI (see GCBO)
% eventdata  structure with the following fields (see MATLAB.UI.FIGURE)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)
    switch(eventdata.Key)
        case 'return'
            saveAndCloseButton_Callback(handles.lvd_viewSettingsGUI, [], handles);
        case 'enter'
            saveAndCloseButton_Callback(handles.lvd_viewSettingsGUI, [], handles);
        case 'escape'
            close(handles.lvd_viewSettingsGUI);
    end

% --- Executes on button press in showSunVectorCheckbox.
function showSunVectorCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to showSunVectorCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showSunVectorCheckbox
    profile = getSelectedProfile(handles);
    profile.showSunVect = logical(get(hObject,'Value'));

% --- Executes on button press in showSunLightingCheckbox.
function showSunLightingCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to showSunLightingCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showSunLightingCheckbox
    profile = getSelectedProfile(handles);
    profile.showLighting = logical(get(hObject,'Value'));

% --- Executes on button press in showScBodyAxesCheckbox.
function showScBodyAxesCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to showScBodyAxesCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showScBodyAxesCheckbox
    profile = getSelectedProfile(handles);
    profile.showScBodyAxes = logical(get(hObject,'Value'));

function scBodyAxesScaleText_Callback(hObject, eventdata, handles)
% hObject    handle to scBodyAxesScaleText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of scBodyAxesScaleText as text
%        str2double(get(hObject,'String')) returns contents of scBodyAxesScaleText as a double
    newInput = get(hObject,'String');
    newInput = attemptStrEval(newInput);
    set(hObject,'String', newInput);

    profile = getSelectedProfile(handles);

    errMsg = {};

    scale = str2double(get(hObject,'String'));
    enteredStr = get(hObject,'String');
    numberName = 'S/C Body Axes Scale';
    lb = 0;
    ub = Inf;
    isInt = false;
    errMsg = validateNumber(scale, numberName, lb, ub, isInt, errMsg, enteredStr);

    if(isempty(errMsg))
        profile.scBodyAxesScale = scale;
    else
        hObject.String = fullAccNum2Str(profile.scBodyAxesScale);

        msgbox(errMsg,'Invalid S/C Body Axes Scale Value','error');
    end

% --- Executes during object creation, after setting all properties.
function scBodyAxesScaleText_CreateFcn(hObject, eventdata, handles)
% hObject    handle to scBodyAxesScaleText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in grdObjsListbox.
function grdObjsListbox_Callback(hObject, eventdata, handles)
% hObject    handle to grdObjsListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns grdObjsListbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from grdObjsListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    grdObjs = viewSettings.lvdData.groundObjs;

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        profile.groundObjsToPlot = grdObjs.getGroundObjsForInds(inds);
    else
        profile.groundObjsToPlot = LaunchVehicleGroundObject.empty(1,0);
    end

% --- Executes during object creation, after setting all properties.
function grdObjsListbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to grdObjsListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in showGrdObjTrksCheckbox.
function showGrdObjTrksCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to showGrdObjTrksCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showGrdObjTrksCheckbox
    profile = getSelectedProfile(handles);
    profile.showGndTracks = logical(get(hObject,'Value'));

% --- Executes on button press in showLoSToScCheckbox.
function showLoSToScCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to showLoSToScCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showLoSToScCheckbox
    profile = getSelectedProfile(handles);
    profile.showGrdObjLoS = logical(get(hObject,'Value'));

% --- Executes on selection change in rendererCombo.
function rendererCombo_Callback(hObject, eventdata, handles)
% hObject    handle to rendererCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns rendererCombo contents as cell array
%        contents{get(hObject,'Value')} returns selected item from rendererCombo
    profile = getSelectedProfile(handles);

    contents = cellstr(get(hObject,'String'));
    str = contents{get(hObject,'Value')};

    profile.renderer = FigureRendererEnum.getEnumForListboxStr(str);

% --- Executes during object creation, after setting all properties.
function rendererCombo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rendererCombo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function meshEdgeAlphaText_Callback(hObject, eventdata, handles)
% hObject    handle to meshEdgeAlphaText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of meshEdgeAlphaText as text
%        str2double(get(hObject,'String')) returns contents of meshEdgeAlphaText as a double
    newInput = get(hObject,'String');
    newInput = attemptStrEval(newInput);
    set(hObject,'String', newInput);

    profile = getSelectedProfile(handles);

    errMsg = {};

    alpha = str2double(get(hObject,'String'));
    enteredStr = get(hObject,'String');
    numberName = 'Mesh Edge Transparency';
    lb = 0;
    ub = 100;
    isInt = false;
    errMsg = validateNumber(alpha, numberName, lb, ub, isInt, errMsg, enteredStr);

    if(isempty(errMsg))
        profile.meshEdgeAlpha = alpha/100;
    else
        hObject.String = fullAccNum2Str(profile.meshEdgeAlpha);

        msgbox(errMsg,'Invalid Mesh Edge Transparency Value','error');
    end

% --- Executes during object creation, after setting all properties.
function meshEdgeAlphaText_CreateFcn(hObject, eventdata, handles)
% hObject    handle to meshEdgeAlphaText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in updateViewAxesCheckbox.
function updateViewAxesCheckbox_Callback(hObject, eventdata, handles)
% hObject    handle to updateViewAxesCheckbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of updateViewAxesCheckbox
    profile = getSelectedProfile(handles);

    profile.updateViewAxesLimits = logical(get(hObject,'Value'));

% --- Executes on button press in showCbAtmo.
function showCbAtmo_Callback(hObject, eventdata, handles)
% hObject    handle to showCbAtmo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of showCbAtmo
    profile = getSelectedProfile(handles);
    profile.showAtmosphere = logical(get(hObject,'Value'));

% --- Executes on selection change in pointsToPlotListbox.
function pointsToPlotListbox_Callback(hObject, eventdata, handles)
% hObject    handle to pointsToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pointsToPlotListbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pointsToPlotListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    pointSet = viewSettings.lvdData.geometry.points;

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        [plotPoints, ~] = pointSet.getPlottablePoints();
        profile.pointsToPlot = plotPoints(inds);
    else
        profile.pointsToPlot = AbstractGeometricPoint.empty(1,0);
    end

% --- Executes during object creation, after setting all properties.
function pointsToPlotListbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pointsToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in vectorsToPlotListbox.
function vectorsToPlotListbox_Callback(hObject, eventdata, handles)
% hObject    handle to vectorsToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns vectorsToPlotListbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from vectorsToPlotListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    vectorSet = viewSettings.lvdData.geometry.vectors;

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        profile.vectorsToPlot = vectorSet.getVectorsForInds(inds);
    else
        profile.vectorsToPlot = AbstractGeometricVector.empty(1,0);
    end

% --- Executes during object creation, after setting all properties.
function vectorsToPlotListbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vectorsToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in refFramessToPlotListbox.
function refFramessToPlotListbox_Callback(hObject, eventdata, handles)
% hObject    handle to refFramessToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns refFramessToPlotListbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from refFramessToPlotListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    refFrameSet = viewSettings.lvdData.geometry.refFrames;

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        profile.refFramesToPlot = refFrameSet.getRefFramesForInds(inds);
    else
        profile.refFramesToPlot = AbstractGeometricRefFrame.empty(1,0);
    end

% --- Executes during object creation, after setting all properties.
function refFramessToPlotListbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to refFramessToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in anglesToPlotListbox.
function anglesToPlotListbox_Callback(hObject, eventdata, handles)
% hObject    handle to anglesToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns anglesToPlotListbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from anglesToPlotListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    angleSet = viewSettings.lvdData.geometry.angles;

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        profile.anglesToPlot = angleSet.getAnglesForInds(inds);
    else
        profile.anglesToPlot = AbstractGeometricAngle.empty(1,0);
    end

% --- Executes during object creation, after setting all properties.
function anglesToPlotListbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to anglesToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in planesToPlotListbox.
function planesToPlotListbox_Callback(hObject, eventdata, handles)
% hObject    handle to planesToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns planesToPlotListbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from planesToPlotListbox
    viewSettings = getappdata(handles.lvd_viewSettingsGUI,'viewSettings');
    planeSet = viewSettings.lvdData.geometry.planes;

    profile = getSelectedProfile(handles);

    inds = hObject.Value;
    if(not(isempty(inds)))
        profile.planesToPlot = planeSet.getPlanesForInds(inds);
    else
        profile.planesToPlot = AbstractGeometricPlane.empty(1,0);
    end

% --- Executes during object creation, after setting all properties.
function planesToPlotListbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to planesToPlotListbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

author: Arrowstar

repo: ksptot

save_path: github-repos/MATLAB/Arrowstar-ksptot


text:
% Script to test INSIDEPOLY

n = 3e2; % number of points
m = 5; % number of vertices

xv = zeros(m,1);
yv = zeros(m,1);

fprintf('Use the mouse and enter %d points of the polygonal\n', m);

figure;
axis equal
axis([0 1 0 1]);
hold on
k = 1;
while k<=m
    [xv(k) yv(k)] = ginput(1);
    if k>1
        plot(xv(k+[-1 0]),yv(k+[-1 0]),'-r');
    else
        plot(xv(1),yv(1),'.r');
    end
    axis([0 1 0 1]);
    k = k+1;
end
plot(xv([end 1]),yv([end 1]),'-r');

x = rand(n,1);
y = rand(n,1);

% xv = [-1 -1 1 1];
% yv = [-1 1 1 -1];
% x=linspace(-2,2,33);
% y=linspace(-2,2,33);
% [x y]=meshgrid(x,y);

in = insidepoly(x, y, xv, yv);

plot(xv([1:end 1]),yv([1:end 1]),'-r');
linestyle={'b.' 'ro'};
hold on
for k=1:numel(x)
    plot(x(k),y(k),linestyle{in(k)+1});
end
drawnow;

%% benchmark
%t = benchinpoly(xv, yv, 100);

author: zhangqianqianQQ

repo: MachineVisionAlgorithm


text:
%% Parzen Probabilistic Neural Networks
%  The Parzen Probabilistic Neural Networks (PPNN) are a simple type of
% neural network used to classify data vectors. This classifiers are based
% on the Bayesian theory where the a posteriori probability density
% function (apo-pdf) is estimated from data using the Parzen window
% technique.

%% A brief overview on the theory of the Parzen window and PPNN
%  The Bayesian classifiers use the Bayesian equation:
%
%                 P(x|wi)P(wi)
%  P(wi|x) = ----------------------
%             SUM_j P(x|wj)P(wj)
%
% to estimate the apo-pdf P(wi|x). Obviously to be usefull, this method
% needs the probabilities P(x|wi) and P(wi) to be known. A technique is to
% parametrize this pdfs, another is to estimate them from data.
%  The Parzen window technique estimates the probability defining a window
% (given the winow size) and a function on this window (i.e. an hypersphere
% with the gaussian function truncated inside). The computes the estimation
% of the probability function convolving the window function with the
% samples function. This obviously requires that the window function must
% have the integral (the hypervolume under the funciton) equal to 1 to
% mantain the scale in the estimated pdf.
%  The PPNN is a simple tool that is the composition of the pdf estimation
% with the Parzen window and the Bayesian classification selecting for a
% feature vector x the class wi where P(wi|x) is maximum.
%  In this quick explanation the particular derivations aren't reported but
% can be found in [1].
%
%  A PPNN is a two layer neural network (NN) where the input data are fully
% connected with the first neuron layer and the first layer is sparsely
% connected with the second (and ouput) layer. The output layer is composed
% of c neurons where c is the number of classes of the classifier.
% The wheights on the first layer are trained as follows: each sample data
% is normalized so that its length becames unitary, each sample data
% becames a neuron with the normalized values as weights w. The input data
% x is so dot-multiplied by the weights obtaining the network activation
% signal net=w^Tx. Then the exponential nonlinearity:
%
%          net - 1
%         ---------
%               2
%           sigm
%  act = e
%
% is computed to obtain the synaptic activation signals. During the
% learning process each first layer neuron is connected to the output layer
% neuron related to its class with wheight 1. During the classification
% process the output neuron of each class sums the activation signals from
% all the neurons of the neurons of the first layer. Simply the highest
% output value selects the class of the input data.
%
%  (w1)  (w2)  ...        OUTPUT
%    \     \ \__
%     |     |    \
%    ( )   ( )   ( )      internal layer
%    /|\   /|\   /|\
%                         INPUT
%
% [1] "Pattern Classification", second edition,
%     by Richard O. Duda, Peter E. Hart. and David G. Stork

%% A first simple example with 2D data
% In this simple example three set of points in the plane are selected in
% the region [1:100;1:100]. A PPNN is trained with this samples and then
% an image of the classification regions is produced.

% A training set for the class 'a' and 'b':
img=ones(100);
f=figure; imshow(img); [X,Y]=getpts; sa=[X,Y]'; close(f);
f=figure; imshow(img); [X,Y]=getpts; sb=[X,Y]'; close(f);
f=figure; imshow(img); [X,Y]=getpts; sc=[X,Y]'; close(f);
% The samples matrix:
S = [sa,sb,sc];
% The classification vector:
C = [repmat('a',[1,size(sa,2)]),repmat('b',[1,size(sb,2)]),repmat('c',[1,size(sc,2)])];
% Generating the network:
net = parzenPNNlearn(S,C);

% Generating the whole grid:
[X,Y] = meshgrid(1:100,1:100);
D = [X(:),Y(:)]';
% Classification of all points:
class = parzenPNNclassify(net,D);
class = reshape(class,[100,100]);
% Plotting:
sep = double(class=='a') + 2*double(class=='c');
figure; imshow(sep/2); hold on;
plot(sa(1,:),sa(2,:),'r.');
plot(sb(1,:),sb(2,:),'g.');
plot(sc(1,:),sc(2,:),'b.');

%% Adding samples to the network to increase the training
%  A PPNN can be simply improved adding new samples to it, the new samples
% generates new neurons in the internal layer that so can grow. Here an
% example of improving of the generated neural network.

% Getting new samples:
f=figure; imshow(img); hold on; plot(sa(1,:),sa(2,:),'r.');
[X,Y]=getpts; nsa=[X,Y]'; close(f);
f=figure; imshow(img); hold on; plot(sb(1,:),sb(2,:),'g.');
[X,Y]=getpts; nsb=[X,Y]'; close(f);
f=figure; imshow(img); hold on; plot(sc(1,:),sc(2,:),'b.');
[X,Y]=getpts; nsc=[X,Y]'; close(f);
Sa = [sa,nsa];
Sb = [sb,nsb];
Sc = [sc,nsc];

% The samples matrix:
nS = [nsa,nsb,nsc];
% The classification vector:
nC = [repmat('a',[1,size(nsa,2)]),repmat('b',[1,size(nsb,2)]),repmat('c',[1,size(nsc,2)])];
% Improving the network:
net = parzenPNNimprove(net,nS,nC);

% Classification of all points:
class = parzenPNNclassify(net,D);
class = reshape(class,[100,100]);
% Plotting:
sep = double(class=='a') + 2*double(class=='c');
figure; imshow(sep/2); hold on;
plot(Sa(1,:),Sa(2,:),'r.');
plot(Sb(1,:),Sb(2,:),'g.');
plot(Sc(1,:),Sc(2,:),'b.');

author: Sable

repo: mcbench-benchmarks


text:
%% Synthetic video demo
% Demonstrates using |VideoSynth| classes as stub for |cv.VideoCapture|.
% Capture object is created using the helper function |createVideoCapture|.
%
% Sources:
%
% * <https://github.com/opencv/opencv/blob/3.3.1/samples/python/video.py>
%

%%
% create synth video capture object
if true
    %cap = createVideoCapture(0, 'aruco');
    cap = createVideoCapture([], 'chess');
else
    %cap = createVideoCapture('synth|class=scene|bg=../test/lena.jpg|fg=../test/mask.png|noise=0.1|size=400x400|speed=1');
    %cap = createVideoCapture('synth|class=scene|bg=../test/fruits.jpg|noise=0.1|size=512x480|speed=1|deformation=true');
    cap = createVideoCapture('synth|class=chess|framecount=500|bg=../test/lena.jpg|size=320x320|noise=0.1|gridsize=9x6');
end
assert(cap.isOpened());

%%
% set a limit on iterations when we're publising demo
if false && isa(cap, 'VideoSynthBase')
    cap.set('FrameCount', 500);
end

%%
% prepare plot
img = cap.read();
assert(~isempty(img));
hImg = imshow(img, 'InitialMagnification',100, 'Border','tight');
hTxt = text(10, 15, 'FPS = 0', 'FontSize',8, 'Color','y');

%%
% main loop
counter = 0;
tID = tic();
while ishghandle(hImg)
    % grab new frame
    img = cap.read();
    if isempty(img); break; end

    % frames-per-second
    counter = counter + 1;
    fps = counter / toc(tID);

    % display
    set(hTxt, 'String',sprintf('FPS = %.2f', fps))
    set(hImg, 'CData',img)
    if ~mexopencv.isOctave()
        drawnow limitrate
    else
        drawnow
    end
end
cap.release();

author: kyamagu

repo: mexopencv

save_path: github-repos/MATLAB/kyamagu-mexopencv


text:
% MatrixUser, a multi-dimensional matrix analysis software package
% https://sourceforge.net/projects/matrixuser/
%
% The MatrixUser is a matrix analysis software package developed under Matlab
% Graphical User Interface Developing Environment (GUIDE). It features
% functions that are designed and optimized for working with multi-dimensional
% matrix under Matlab. These functions typically includes functions for
% multi-dimensional matrix display, matrix (image stack) analysis and matrix
% processing.
%
% Author:
%   Fang Liu <leoliuf@gmail.com>
%   University of Wisconsin-Madison
%   Aug-30-2014

function [T, R]=rotate3DT_MU(o, v, theta, interp)
% Generate TFORM for rotating 3D volume with an angle of theta along any spatial vector v;
% Im input 3D matrix
% o  rotating origion
% v  rotating axis
% theta rotating angle
% interp interp method

% T TFORM structure
% R resampling structure
% Note: by default the center voxel in Im was set as rotating origin.

T1 = [1 0 0 0
      0 1 0 0
      0 0 1 0
      -o(2), -o(1), -o(3) 1]; % forward translate matrix

T2 = angvec2tr(theta, v); % 3D rotate matrix

T3= [1 0 0 0
     0 1 0 0
     0 0 1 0
     o(2), o(1), o(3) 1]; % backward translate matrix

T = T1*T2*T3; % total transform matrix

T = maketform('affine', T);
R = makeresampler(interp, 'fill');

author: leoliuf

repo: MRiLab

save_path: github-repos/MATLAB/leoliuf-MRiLab


text:
% Change to your downloaded location
clear
addpath('C:\liblinear\matlab')
addpath('../training_code/');
addpath('../utilities/');
addpath('../../data extraction/');

%% load shared definitions and AU data
all_dataset_aus = [1, 2, 4, 6, 7, 10, 12, 15, 17, 23, 25, 26, 45];

% Set up the hyperparameters to be validated
hyperparams.c = 10.^(-8:0.5:4);
hyperparams.p = 10.^(-2);

hyperparams.validate_params = {'c', 'p'};

% Set the training function
svr_train = @svr_train_linear;

% Set the test function (the first output will be used for validation)
svr_test = @svr_test_linear;

BP4D_aus = [6, 10, 12, 14, 17];
UNBC_aus = [6, 7, 9, 12, 25, 26];
DISFA_aus = [1, 2, 4, 5, 6, 9, 12, 15, 17, 20, 25, 26];
Bosphorus_aus = [1, 2, 4, 5, 6, 7, 9, 10, 12, 14, 15, 17, 20, 23, 25, 26, 45];

for a=1:numel(all_dataset_aus)

    au = all_dataset_aus(a);

    train_samples = [];
    valid_samples = [];

    train_labels = [];
    valid_labels = [];

    % Keeping track which validation sample came from which dataset, as we
    % will be validating based on which hyperparam leads to best
    % performance on all datasets (mean F1)
    eval_ids = [];
    dataset_ids = {};
    vid_ids = {};
    success = [];

    if(~isempty(find(BP4D_aus == au, 1)))
        op = cd('../BP4D/');
        rest_aus = setdiff(BP4D_aus, au);
        shared_defs;
        % load the training and testing data for the current fold
        [train_samples_bp4d, train_labels_bp4d, ~, valid_samples_bp4d, valid_labels_bp4d, vid_ids_bp4d, ~, PC, means, scaling, success_devel] = Prepare_HOG_AU_data_generic_intensity(train_recs, devel_recs, au, BP4D_dir_int, hog_data_dir);

        ignore = valid_labels_bp4d == 9;

        valid_samples_bp4d = valid_samples_bp4d(~ignore, :);
        valid_labels_bp4d = valid_labels_bp4d(~ignore);
        vid_ids_bp4d = vid_ids_bp4d(~ignore);
        success_devel = success_devel(~ignore);

        train_samples = cat(1, train_samples, train_samples_bp4d);
        valid_samples = cat(1, valid_samples, valid_samples_bp4d);

        train_labels = cat(1, train_labels, train_labels_bp4d);
        valid_labels = cat(1, valid_labels, valid_labels_bp4d);
        vid_ids = cat(1, vid_ids, vid_ids_bp4d);

        success = cat(1, success, success_devel);

        if(isempty(eval_ids))
           eval_ids = ones(size(valid_labels_bp4d,1), 1);
        end

        clear 'train_samples_bp4d' 'train_labels_bp4d' 'valid_samples_bp4d' 'valid_labels_bp4d'

        dataset_ids = cat(1, dataset_ids, {'BP4D'});

        cd(op);

    end

   if(~isempty(find(Bosphorus_aus == au, 1)))
        op = cd('../Bosphorus/');
        rest_aus = setdiff(DISFA_aus, au);
        shared_defs;

        % make sure validation data's labels are balanced
        [users_train, users_valid_bosph] = get_balanced_fold(Bosphorus_dir, all_recs, au, 1/3, 1);

        % need to split the rest
        [train_samples_bosph, train_labels_bosph, valid_samples_bosph, valid_labels_bosph, ~, PC, means, scaling, valid_ids, valid_success] = Prepare_HOG_AU_data(users_train, users_valid_bosph, au, rest_aus, Bosphorus_dir, hog_data_dir);

        % As there are only a few Bosphorus images (it being an image dataset)
        % we oversample it quite a bit
        train_samples_bosph = repmat(train_samples_bosph, 10, 1);
        train_labels_bosph = repmat(train_labels_bosph, 10, 1);

        train_samples = cat(1, train_samples, train_samples_bosph);
        valid_samples = cat(1, valid_samples, valid_samples_bosph);

        train_labels = cat(1, train_labels, train_labels_bosph);
        valid_labels = cat(1, valid_labels, valid_labels_bosph);

        vid_ids = cat(1, vid_ids, valid_ids);

        success = cat(1, success, valid_success);

        if(isempty(eval_ids))
           eval_ids = ones(size(valid_labels_bosph, 1), 1);
        else
           eval_ids = cat(1, eval_ids, (eval_ids(end)+1)*ones(size(valid_labels_bosph, 1), 1));
        end

        clear 'train_samples_bosph' 'train_labels_bosph' 'valid_samples_bosph' 'valid_labels_bosph'
        dataset_ids = cat(1, dataset_ids, {'Bosphorus'});
        cd(op);

    end

    if(~isempty(find(DISFA_aus == au, 1)))
        op = cd('../DISFA/');
        rest_aus = setdiff(DISFA_aus, au);
        shared_defs;

        % make sure validation data's labels are balanced
        [users_train, users_valid_disfa] = get_balanced_fold(DISFA_dir, users, au, 1/3, 1);

        % need to split the rest
        [train_samples_disf, train_labels_disf, valid_samples_disf, valid_labels_disf, raw_disfa, PC, means, scaling, vid_ids_disfa, valid_success] = Prepare_HOG_AU_data_generic(users_train, users_valid_disfa, au, rest_aus, DISFA_dir, hog_data_dir);

        train_samples = cat(1, train_samples, train_samples_disf);
        valid_samples = cat(1, valid_samples, valid_samples_disf);

        train_labels = cat(1, train_labels, train_labels_disf);
        valid_labels = cat(1, valid_labels, valid_labels_disf);

        vid_ids = cat(1, vid_ids, vid_ids_disfa);

        success = cat(1, success, valid_success);

        if(isempty(eval_ids))
           eval_ids = ones(size(valid_labels_disf,1), 1);
        else
           eval_ids = cat(1, eval_ids, (eval_ids(end)+1)*ones(size(valid_labels_disf,1), 1));
        end

        clear 'train_samples_disf' 'train_labels_disf' 'valid_samples_disf' 'valid_labels_disf'
        dataset_ids = cat(1, dataset_ids, {'DISFA'});
        cd(op);

    end

    if(~isempty(find(UNBC_aus == au, 1)))
        op = cd('../UNBC/');
        rest_aus = setdiff(UNBC_aus, au);
        shared_defs;

        [users_train, users_valid_unbc] = get_balanced_fold(UNBC_dir, all_recs, au, 1/3, 1);

        % load the training and testing data for the current fold
        [train_samples_unbc, train_labels_unbc, valid_samples_unbc, valid_labels_unbc, ~, PC, means, scaling, vid_ids_unbc, success_devel] = Prepare_HOG_AU_data(users_train, users_valid_unbc, au, rest_aus, UNBC_dir, features_dir);

        train_samples = cat(1, train_samples, train_samples_unbc);
        valid_samples = cat(1, valid_samples, valid_samples_unbc);

        train_labels = cat(1, train_labels, train_labels_unbc);
        valid_labels = cat(1, valid_labels, valid_labels_unbc);

        vid_ids = cat(1, vid_ids, vid_ids_unbc);

        success = cat(1, success, success_devel);

        if(isempty(eval_ids))
           eval_ids = ones(size(valid_labels_unbc,1), 1);
        else
           eval_ids = cat(1, eval_ids, (eval_ids(end)+1)*ones(size(valid_labels_unbc,1), 1));
        end

        clear 'train_samples_unbc' 'train_labels_unbc' 'valid_samples_unbc' 'valid_labels_unbc'
        dataset_ids = cat(1, dataset_ids, {'UNBC'});
        cd(op);

    end

    train_samples = sparse(train_samples);
    dataset_ids
    %% Cross-validate here

    name = sprintf('mat_models/AU_%d_static_intensity.mat', au);
    load(name, 'model');
    model_reg = model;

    valid_all_reg = valid_samples * model_reg.w(1:end-1)' + model_reg.w(end);
    train_all_reg = train_samples * model_reg.w(1:end-1)' + model_reg.w(end);

    name = sprintf('mat_models/AU_%d_static.mat', au);
    load(name, 'model');
    model_class = model;
    valid_all_class = valid_samples * model_class.w(1:end-1)' + model_class.w(end);
    train_all_class = train_samples * model_class.w(1:end-1)' + model_class.w(end);

    valid_samples_p = cat(2, valid_all_reg, valid_all_class);
    train_samples_p = sparse(cat(2, train_all_reg, train_all_class));

    %%
    hyperparams.eval_ids = eval_ids;
    hyperparams.vid_ids = vid_ids;
    hyperparams.valid_samples = valid_samples_p;
    hyperparams.success = success;
    hyperparams.valid_labels = valid_labels;

    [ best_params, ~ ] = validate_grid_search_no_par(svr_train, svr_test, false, train_samples_p, train_labels, valid_samples_p, valid_labels, hyperparams);
    model_fuse = svr_train(train_labels, train_samples_p, best_params);

    % Fust the regressor and classifier based on their corresponding
    % weights
    p = model_fuse.w;
    model = model_reg;
    model.w = model_reg.w * p(1)  + model_class.w * p(2);
    model.w(end) = model.w(end) + p(3);
    %%
    name = sprintf('mat_models/AU_%d_static_intensity_comb.mat', au);

    [~, predictions_all] = svr_test(valid_labels, valid_samples, model);

    eval_ids_uq = unique(eval_ids)';
    cccs = [];
    for i=eval_ids_uq
        [ ~, ~, ~, ccc_c, ~, ~ ] = evaluate_regression_results( predictions_all(eval_ids==i), valid_labels(eval_ids==i));
        cccs = cat(2, cccs, ccc_c);
    end

    mean_ccc = mean(cccs);
    %%
    save(name, 'model', 'mean_ccc', 'mean_ccc', 'cccs', 'predictions_all', 'valid_labels', 'eval_ids', 'dataset_ids');

    % Write out the model
    name = sprintf('regressors/AU_%d_static_intensity_comb.dat', au);

    w = model.w(1:end-1)';
    b = model.w(end);

    svs = bsxfun(@times, PC, 1./scaling') * w;

    write_lin_svr(name, means, svs, b);

    clear 'train_samples' 'train_labels' 'valid_samples' 'valid_labels'
end

author: TadasBaltrusaitis

repo: OpenFace


text:
%
% Usage:   [D [model]]=mexTrainDL(X,param[,model]);
%          model is optional
%
% Name: mexTrainDL
%
% Description: mexTrainDL is an efficient implementation of the
%     dictionary learning technique presented in
%
%     "Online Learning for Matrix Factorization and Sparse Coding"
%     by Julien Mairal, Francis Bach, Jean Ponce and Guillermo Sapiro
%     arXiv:0908.0050
%
%     "Online Dictionary Learning for Sparse Coding"
%     by Julien Mairal, Francis Bach, Jean Ponce and Guillermo Sapiro
%     ICML 2009.
%
%     Note that if you use param.mode=1 or 2, if the training set has a
%     reasonable size and you have enough memory on your computer, you
%     should use mexTrainDL_Memory instead.
%
%
%     It addresses the dictionary learning problems
%        1) if param.mode=0
%     min_{D in C} (1/n) sum_{i=1}^n (1/2)||x_i-Dalpha_i||_2^2  s.t. ...
%                                                  ||alpha_i||_1 <= lambda
%        2) if param.mode=1
%     min_{D in C} (1/n) sum_{i=1}^n  ||alpha_i||_1  s.t.  ...
%                                           ||x_i-Dalpha_i||_2^2 <= lambda
%        3) if param.mode=2
%     min_{D in C} (1/n) sum_{i=1}^n (1/2)||x_i-Dalpha_i||_2^2 + ...
%                                  lambda||alpha_i||_1 + lambda_2||alpha_i||_2^2
%        4) if param.mode=3, the sparse coding is done with OMP
%     min_{D in C} (1/n) sum_{i=1}^n (1/2)||x_i-Dalpha_i||_2^2  s.t. ...
%                                                  ||alpha_i||_0 <= lambda
%        5) if param.mode=4, the sparse coding is done with OMP
%     min_{D in C} (1/n) sum_{i=1}^n  ||alpha_i||_0  s.t.  ...
%                                           ||x_i-Dalpha_i||_2^2 <= lambda
%        6) if param.mode=5, the sparse coding is done with OMP
%     min_{D in C} (1/n) sum_{i=1}^n 0.5||x_i-Dalpha_i||_2^2 +lambda||alpha_i||_0
%
%
%     C is a convex set verifying
%        1) if param.modeD=0
%           C={  D in Real^{m x p}  s.t.  forall j,  ||d_j||_2^2 <= 1 }
%        2) if param.modeD=1
%           C={  D in Real^{m x p}  s.t.  forall j,  ||d_j||_2^2 + ...
%                                                  gamma1||d_j||_1 <= 1 }
%        3) if param.modeD=2
%           C={  D in Real^{m x p}  s.t.  forall j,  ||d_j||_2^2 + ...
%                                  gamma1||d_j||_1 + gamma2 FL(d_j) <= 1 }
%        4) if param.modeD=3
%           C={  D in Real^{m x p}  s.t.  forall j,  (1-gamma1)||d_j||_2^2 + ...
%                                  gamma1||d_j||_1 <= 1 }
%
%     Potentially, n can be very large with this algorithm.
%
% Inputs: X:  double m x n matrix   (input signals)
%               m is the signal size
%               n is the number of signals to decompose
%         param: struct
%            param.D: (optional) double m x p matrix   (dictionary)
%              p is the number of elements in the dictionary
%              When D is not provided, the dictionary is initialized
%              with random elements from the training set.
%           param.K (size of the dictionary, optional is param.D is provided)
%           param.lambda  (parameter)
%           param.lambda2  (optional, by default 0)
%           param.iter (number of iterations).  If a negative number is
%              provided it will perform the computation during the
%              corresponding number of seconds. For instance param.iter=-5
%              learns the dictionary during 5 seconds.
%           param.mode (optional, see above, by default 2)
%           param.posAlpha (optional, adds positivity constraints on the
%             coefficients, false by default, not compatible with
%             param.mode =3,4)
%           param.modeD (optional, see above, by default 0)
%           param.posD (optional, adds positivity constraints on the
%             dictionary, false by default, not compatible with
%             param.modeD=2)
%           param.gamma1 (optional parameter for param.modeD >= 1)
%           param.gamma2 (optional parameter for param.modeD = 2)
%           param.batchsize (optional, size of the minibatch, by default
%              512)
%           param.iter_updateD (optional, number of BCD iterations for the dictionary
%              update step, by default 1)
%           param.modeParam (optimization mode).
%              1) if param.modeParam=0, the optimization uses the
%                 parameter free strategy of the ICML paper
%              2) if param.modeParam=1, the optimization uses the
%                 parameters rho as in arXiv:0908.0050
%              3) if param.modeParam=2, the optimization uses exponential
%                 decay weights with updates of the form
%                 A_{t} <- rho A_{t-1} + alpha_t alpha_t^T
%           param.rho (optional) tuning parameter (see paper arXiv:0908.0050)
%           param.t0 (optional) tuning parameter (see paper arXiv:0908.0050)
%           param.clean (optional, true by default. prunes
%              automatically the dictionary from unused elements).
%           param.verbose (optional, true by default, increase verbosity)
%           param.numThreads (optional, number of threads for exploiting
%              multi-core / multi-cpus. By default, it takes the value -1,
%              which automatically selects all the available CPUs/cores).
%
% Output:
%         param.D: double m x p matrix   (dictionary)
%
% Note: this function admits a few experimental usages, which have not
%     been extensively tested:
%         - single precision setting
%
% Author: Julien Mairal, 2009

author: qMRLab

repo: qMRLab

save_path: github-repos/MATLAB/qMRLab-qMRLab


text:
 function jf_assert(varargin)
%function jf_assert(command)
% verify that the command (evaluated within caller) returns true.
% if not, print error message.

if nargin < 1, ir_usage, end
if nargin == 1 && streq(varargin{1}, 'test'), jf_assert_test, return, end

arg = [varargin{:}]; % handle cases with spaces like 'jf_assert x == y'

[name line] = caller_name;
if isempty(name)
	str = '';
else
	str = sprintf(' at %d in "%s"', line, name);
end

try
	tmp = evalin('caller', arg);
catch
	error(['%s was unable to evaluate "%s"' str], mfilename, arg)
end

% note: use isequal, not issame!
if isscalar(tmp) && islogical(tmp)
	if ~tmp
		fail(['jf_assert of "%s" was untrue' str], arg)
%		dbup
%		dbstack
%		keyboard
	end
else
tmp
	whos
	error(['jf_assert of "%s" did not return logical scalar' str], arg)
end

function jf_assert_test
jf_assert 7 == 7

author: JeffFessler

repo: mirt

save_path: github-repos/MATLAB/JeffFessler-mirt


text:
% --------- DeepMIMO: A Generic Dataset for mmWave and massive MIMO ------%
% Authors: Ahmed Alkhateeb, Umut Demirhan, Abdelrahman Taha
% Date: March 17, 2022
% Goal: Encouraging research on ML/DL for MIMO applications and
% providing a benchmarking tool for the developed algorithms
% ---------------------------------------------------------------------- %

function params = read_params(filename)
    run(filename)
end

author: DeepMIMO

repo: DeepMIMO-matlab


text:
function doomsday_test ( )

%*****************************************************************************80
%
%% DOOMSDAY_TEST tests the DOOMSDAY library.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    28 May 2012
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'DOOMSDAY_TEST:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Test the DOOMSDAY library.\n' );

  doomsday_test01 ( );
  doomsday_test02 ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'DOOMSDAY_TEST:\n' );
  fprintf ( 1, '  Test the DOOMSDAY library.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end

author: johannesgerer

repo: jburkardt-m


text:
%{
load('dataset/trafficdb/traffic_patches.mat');
[M,m,n,p] = convert_video3d_to_2d(im2double(imgdb{100}));
out = run_algorithm('MC', 'MC-NMF', M, [])
show_results(M.*out.Omega,out.L,out.S,out.O,p,m,n);
%}

MIdx = M(Idx);

[m,n] = size(M);
r = 2; t = 1;
esr = ceil(t*r);

opts.tol = 1e-5;
opts.maxit = 500;
opts.print = 1;

[X,Y,Out] = mc_nmf(MIdx,Idx,esr,m,n,opts);
L = X*Y; % low-rank
S = (M - L); % sparse

author: andrewssobral

repo: lrslibrary


text:
function value = r8_asin ( x )

%*****************************************************************************80
%
%% R8_ASIN evaluates the arc-sine of an R8 argument.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    25 September 2011
%
%  Author:
%
%    Original FORTRAN77 version by Wayne Fullerton.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Wayne Fullerton,
%    Portable Special Function Routines,
%    in Portability of Numerical Software,
%    edited by Wayne Cowell,
%    Lecture Notes in Computer Science, Volume 57,
%    Springer 1977,
%    ISBN: 978-3-540-08446-4,
%    LC: QA297.W65.
%
%  Parameters:
%
%    Input, real X, the argument.
%
%    Output, real VALUE, the arc-sine of X.
%
  persistent asincs
  persistent nterms
  persistent sqeps

  if ( isempty ( nterms ) )
    asincs = [ ...
    +0.10246391753227159336573148305785E+00, ...
    +0.54946487221245833306011195902924E-01, ...
    +0.40806303925449692851307056149246E-02, ...
    +0.40789006854604435455598823905612E-03, ...
    +0.46985367432203691616048530136218E-04, ...
    +0.58809758139708058986454385552074E-05, ...
    +0.77732312462777632750557528163795E-06, ...
    +0.10677423340082039235047504956587E-06, ...
    +0.15092399536022808262386434401064E-07, ...
    +0.21809724080055385496609614713930E-08, ...
    +0.32075984262789614433261959667376E-09, ...
    +0.47855369646781034461493133918953E-10, ...
    +0.72251287362910432263848754537112E-11, ...
    +0.11018334742255783705372701334987E-11, ...
    +0.16947632539203354877423745651078E-12, ...
    +0.26261558667348224162283241502416E-13, ...
    +0.40958299813281178408828069291110E-14, ...
    +0.64244793108803655891727944887091E-15, ...
    +0.10128142198228221693973361222041E-15, ...
    +0.16039221897380787560050597464746E-16, ...
    +0.25503501355807141715298789676373E-17, ...
    +0.40701403797862382855487165672106E-18, ...
    +0.65172671712881144437889267575466E-19, ...
    +0.10467453037096796954244891716266E-19, ...
    +0.16858725563380328094989095185066E-20, ...
    +0.27221936305040227625164341247999E-21, ...
    +0.44059293900347550617126830079999E-22, ...
    +0.71466685243375937853063168000000E-23, ...
    +0.11615793343859516051798971733333E-23, ...
    +0.18915234552354685801184187733333E-24, ...
    +0.30855772044244342399827968000000E-25, ...
    +0.50416366022162453412970495999999E-26, ...
    +0.82502725502400865081753600000000E-27, ...
    +0.13520032631020947208055466666666E-27, ...
    +0.22184326876541720216644266666666E-28, ...
    +0.36442494054085079212578133333333E-29, ...
    +0.59920218558643813307733333333333E-30, ...
    +0.98584812059573785810261333333333E-31, ...
    +0.16222501166399014393173333333333E-31 ]';
    nterms = r8_inits ( asincs, 39, 0.1 * r8_mach ( 3 ) );
    sqeps = sqrt ( 6.0 * r8_mach ( 3 ) );
  end

  y = abs ( x );

  if ( x < - 1.0 - sqeps )

    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8_ASIN - Fatal error!\n' );
    fprintf ( 1, '  X < - 1.0\n' );
    error ( 'R8_ASIN - Fatal error!' )

  elseif ( x < - 1.0 )

    value = - 0.5 * pi;

  elseif ( x < 1.0 )

    z = 0.0;
    if ( sqeps < y )
      z = y * y;
    end

    if ( z <= 0.5 )
      value = x * ( 1.0 + r8_csevl ( 4.0 * z - 1.0, asincs, nterms ) );
    else
      value = 0.5 * pi - sqrt ( 1.0 - z ) * ( 1.0 + ...
        r8_csevl ( 3.0 - 4.0 * z, asincs, nterms ) );
    end

    if ( x < 0.0 )
      value = - abs ( value );
    elseif ( 0.0 < x )
      value = + abs ( value );
    end

  elseif ( x < 1.0 + sqeps )

    value = 0.5 * pi;

  else

    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8_ASIN - Fatal error!\n' );
    fprintf ( 1, '  1.0 < X\n' );
    error ( 'R8_ASIN - Fatal error!' )

  end

  return
end


text:
function [bar] = kPa2bar(kPa)
% Convert pressure from kilopascals to bar.  It's interesting how we tend
% to say "bar" as the plural for "bar".  I've heard people say "millibars"
% but I've also heard "millibar" as its plural.  The same does not seem to
% be true for other units of pressure.  We'd say "5 atmospheres".  For some
% reason, I often hear people talk about singular form of animals as their
% plural, too.  Of course there's deer and fish, but I'm not talking about
% those.  I've actually heard people say "Look at those alpaca" or "we saw
% some bear" or "There are lots of squirrel out today".  Strange.
% Chad A. Greene 2012
bar = kPa/100;


text:
function [dc, dh, d_emb, grad_W_rnn, d_feed_input] = rnnStepLayerBackprop(W_rnn, prev_state, cur_state, cur_top_grad, dc, dh, ...
  maskInfo, params, isFeedInput)
% Backprop multi-layer RNN for one time step.
% Input:
%   W_rnn: recurrent connections of multiple layers, e.g., W_rnn{ll}.
%   prevState: previous hidden state, e.g., for LSTM, prevState.c{ll}, prevState.h{ll}.
%   curState: current hidden state, e.g., for LSTM, curState.c{ll}, curState.h{ll}.
%
% Output:
%
% Thang Luong @ 2015, <lmthang@stanford.edu>

numLayers = length(W_rnn);

unmaskedIds = maskInfo.unmaskedIds;
maskedIds = maskInfo.maskedIds;
grad_W_rnn = cell(numLayers, 1);
for ll=numLayers:-1:1 % layer
  % add grad from the top
  if ~isempty(cur_top_grad)
    dh{ll}(:, unmaskedIds) = dh{ll}(:, unmaskedIds) + cur_top_grad(1:params.lstmSize, unmaskedIds);
  end

  % cell backprop
  [dc{ll}, dh{ll}, d_input, grad_W_rnn{ll}] = lstmUnitBackprop(W_rnn{ll}, cur_state{ll}, prev_state{ll}.c_t, dc{ll}, dh{ll}, maskedIds, ...
    params, ll==1 && isFeedInput);

  % pass down hidden state grad to the below layer
  cur_top_grad = d_input;
end

% emb
d_emb = d_input(1:params.lstmSize, :);

% feed softmax vector
if isFeedInput
  d_feed_input = d_input(params.lstmSize+1:2*params.lstmSize, :);
else
  d_feed_input = [];
end

author: lmthang


text:
% MatrixUser, a multi-dimensional matrix analysis software package
% https://sourceforge.net/projects/matrixuser/
%
% The MatrixUser is a matrix analysis software package developed under Matlab
% Graphical User Interface Developing Environment (GUIDE). It features
% functions that are designed and optimized for working with multi-dimensional
% matrix under Matlab. These functions typically includes functions for
% multi-dimensional matrix display, matrix (image stack) analysis and matrix
% processing.
%
% Author:
%   Fang Liu <leoliuf@gmail.com>
%   University of Wisconsin-Madison
%   Aug-30-2014

function MU_funcSin(Temp,Event,handles)
handles = guidata(handles.MU_matrix_display);

MergeM=get(handles.Matrix_name_edit,'String');
if isfloat(handles.TMatrix(1))
    set(handles.Matrix_name_edit,'String',['sin([' MergeM '])']);
else
    set(handles.Matrix_name_edit,'String',['sin(double([' MergeM ']))']);
end
MU_calc_matrix(handles);

end


text:
%  追赶法 分解的紧凑方式
function [x] = my_forward_backward(A,f)

[m,n]=size(A);
if (m~=n)
    fprintf('\n Error: A 不是方阵!\n'); return;
end

a = diag(A, -1);
a(2:n) = a;
a(1) = 0;
b = diag(A);
c = diag(A, 1);

% 判断是否三对角矩阵
if sum(any(tril(A, -2))) > 0 | sum(any(triu(A, 2))) > 0
    fprintf('\n Error: A 不是三对角矩阵!\n'); x = [];  return;
end

% 判断是否对角占优
if (abs(b(1)) <= abs(c(1)) | abs(c(1)) == 0 | find(abs(b(2:n-1)) < abs(a(2:n-1)) + abs(c(2:n-1))) > 0 | abs(b(n)) <= abs(a(n))) | abs(a(n)) == 0
  fprintf('\n Error: A 不是对角占优矩阵!\n'); x = [];  return;
end

alpha = zeros(n, 1);
beda = zeros(n-1, 1);
gamma = a;   % gamma直接等于a，无需计算

alpha(1) = b(1);
for i = 1 : n - 1
    beda(i) = c(i) / alpha(i);
    alpha(i + 1) = b(i + 1) - a(i + 1) * beda(i);
end

% 求解Ly=b 和 Ux=y
y(1) = f(1) / b(1);
for i=2:n
    y(i)=(f(i) - a(i)*y(i-1)) / alpha(i);
end
x(n) = y(n);
for i = n-1 : -1 : 1
    x(i)=y(i) - beda(i) * x(i+1);
end

% END

repo: NumericalAnalysis