如何在matlab gui中实现mvc设计的思想

发布于 2024-09-14 07:27:41 字数 8684 浏览 5 评论 0原文

我是一名学生,正在开发一个可视化工具,以便在 Matlab 中使用 MVC 设计来分析数据。但我遇到的问题是,我对编程很陌生,而 matlab 是我第一次真正进行编程。我几乎完成了这些代码,但我担心它们在 MVC 设计模式中是不可能的,所以我需要更改它。

我真的很感激尽可能多的估算,将我与有用的材料联系起来,因为我在 matlab 中找不到任何 mvc 的东西,或者可能是在 matlab 中实现 mvc 的示例代码,以帮助我了解我目前和正在做的事情像这样的东西,其中数据是带有 .Name 和 .Data 字段的结构。函数/方法 datcorrCoef 和 datCorrSum 是我创建的函数,它们接受我的数据对象作为参数


function dataAnalysisGUI(data)

fdataAnalysisGUI = figure('Name','Data Analysis ',...
    'tag','dataAnalysisGUI',...
    'menu','none',...
    'units','normalized',...
    'NumberTitle', 'off')



%%% intialise the gui with data set to work with
vtDaUD.opD = data;



Rsq = datcorrCoef(vtDaUD.opD);
opit = datWrappa(Rsq);
vtDaUD.wd = opit;
vtDaUD.feel = datCorrSum(data);
%%%------------------- menus ------------------------------------------%%%
smh = uimenu('Label', 'Sort', 'Tag', 'daSortMenu');
cmh = uimenu(smh, 'Label', 'Sum of CorrCoeff ',...
    'Tag', 'correlation');
    uimenu(cmh, 'Label', 'Increasing ',...
    'Tag', 'cIncreasing',...
    'callback','vtDaCallbacks(''cIncreasing_callback'')');
    uimenu(cmh, 'Label', 'Decreasing ',...
    'Tag', 'cDecreasing',...
    'callback','vtDaCallbacks(''cDecreasing_callback'')');
mmh = uimenu(smh, 'Label', 'Max Lag ',...
    'Tag', 'maxLag');
    uimenu(mmh, 'Label', 'Increasing ',...
    'Tag', 'mIncreasing',...
    'callback','vtDaCallbacks(''mIncreasing_callback'')');
    uimenu(mmh, 'Label', 'Decreasing ',...
    'Tag', 'mDecreasing',...
    'callback','vtDaCallbacks(''mDecreasing_callback'')');



dmh = uimenu('Label', 'Display', 'Tag', 'daDisplayMenu');
            uimenu(dmh, 'Label', 'Scatter Plots ',...
                  'Tag', 'dScatter',...
                  'Callback','vtDaCallbacks(''dScatter_callback'')');
              uimenu(dmh, 'Label', 'Cross Correlation ',...
                  'Tag', 'dCrosscorr',...
                  'callback','vtDaCallbacks(''dCrosscorr_callback'')');
              uimenu(dmh, 'Label', 'Time Series ',...
                  'Tag', 'dTimeseries',...
                  'callback','vtDaCallbacks(''dTimeseries_callback'')');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%------------------------ panels ------------------------------------%%%
 vtDaPanel1 = uipanel(fdataAnalysisGUI,...
       'Units','normalized',...
       'Position', [.025 .035 .84 .95],...
       'FontSize',10,...
       'tag','vtDaPanel1',...
       'backgroundcolor',[0.8, 0.8,0.8],...
       'title', 'Table of Cross Correlations between Data');
    vtDaPanel2 = uipanel(fdataAnalysisGUI,...
       'Units','normalized',...
       'Position', [.87 .566 .12 .396],...
       'tag','vtDaPanel2',...
       'backgroundcolor',[0.8, 0.8,0.8],...
       'title', 'Analysis');

   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %%%------------------------- objects -------------------------------%%%
        uitable('parent', vtDaPanel1,...
            'tag','vtDaTable',...
            'RearrangeableColumn', 'on',...
            'clipping','off',...
            'Units','normalized',...
            'Position',[.01 .2 .98 .8],...
            'data',opit.Data,...
            'rowname',opit.Name,...
            'columnname',opit.Name,...
            'CellSelectionCallback',{@daTable_callback,vtDaUD.opD});

        uitable('parent', vtDaPanel1,...
            'tag','vtDaTable2',...
            'RearrangeableColumn', 'on',...
            'Units','normalized',...
            'Position',[.01 .01 .98 .15],...
            'data',vtDaUD.feel.Data,...
            'rowname','Sum of Corr. Coeff',...
            'columnname',vtDaUD.feel.Name,...
            'TooltipString','select column header to drill down',...
            'CellSelectionCallback',{@daTable2_callback,vtDaUD.opD});


        uicontrol(vtDaPanel2, 'Style', 'popupmenu',...
            'tag','taskpopMenu',...
            'Units','normalized',...
            'Position', [.10 .75 .8 .1],...
            'String', {'Correlation Coeff';'Max lags'},...
            'Callback', 'vtDaCallbacks(''taskpopMenu_callback'')');

        uicontrol(vtDaPanel2, 'Style', 'text',...
            'tag','staticTxt2',...
            'Units','normalized',...
            'Position', [.10 .86 .8 .05],...
            'String', {'Task'});

        uicontrol(vtDaPanel2, 'Style', 'text',...
            'tag','staticTxt3',...
            'Units','normalized',...
            'Position', [.10 .61 .8 .05],...
            'String', {'Mini Display'});

        uicontrol(vtDaPanel2, 'Style', 'pushbutton',...
            'tag','pushTimeseries',...
            'Units','normalized',...
            'Position', [.10 .5 .8 .1],...%[450 350 100 50]
            'String', {'TimeSeries'},...
            'Callback', 'vtDaCallbacks(''pushTimeseries_callback'')');

        uicontrol(vtDaPanel2, 'Style', 'pushbutton',...
            'tag','pushScatter',...
            'Units','normalized',...
            'Position', [.10 .35 .8 .1],...
            'String', {'Scatter'},...
            'Callback', 'vtDaCallbacks(''pushScatter_callback'')');

        uicontrol(vtDaPanel2, 'Style', 'pushbutton',...
            'tag','pushMaxlag',...
            'Units','normalized',...
            'Position', [.10 .2 .8 .1],...
            'String', {'Max Lag'},...
            'Callback', 'vtDaCallbacks(''pushMaxlag_callback'')');


name = genvarname(['daGUI' data.Name{2}]);%name = datname('daGUI',lenght(data.Name));
vtDaUD.varName = name;
eval([name '= data.Data']);
assignin('base',name,data.Data);


set(fdataAnalysisGUI,'UserData',vtDaUD)

,并且我已完成回调/控制,如下所示;

function vtDaCallbacks(action)
handles = guihandles(gcf);
vtDaUD = get(handles.dataAnalysisGUI,'UserData');
%tabdata=get(handles.vtDaTable,'data');
tab2Data.Data = get(handles.vtDaTable2,'data');
tab2Data.Name = get(handles.vtDaTable2,'columnname');


switch action
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%-----------------------Data AnalysisGUI menu callbacks-----------%%%
    case 'cIncreasing_callback'
        [newTabData,index] = sortaColumn(tab2Data,'ascend',1);
        vtDaUD.wd = dataselect(vtDaUD.opD,index);
        set(handles.vtDaTable2, 'data', newTabData.Data)
        set(handles.vtDaTable2, 'columnname', newTabData.Name)
        set(handles.vtDaTable2,'CellSelectionCallback',{@daTable2_callback,vtDaUD.wd});


    case 'cDecreasing_callback'
        [newTabData,index] = sortaColumn(tab2Data,'descend',1);
        vtDaUD.wd = dataselect(vtDaUD.opD,index);
        %[vtDaUD.wd,newTabData,newcolumnname] = sortta2(vtDaUD.opD,'descend',tab2Data,1);
        set(handles.vtDaTable2, 'data', newTabData.Data)
        set(handles.vtDaTable2, 'columnname', newTabData.Name)
        set(handles.vtDaTable2,'CellSelectionCallback',{@daTable2_callback,vtDaUD.wd});

    case 'dScatter_callback'
        dataDispGUI('dScatta','calnumpage2',vtDaUD.opD, 'Scatter Plots')

    case 'dTimeseries_callback'
        dataDispGUI('dTimeSeries2','calnumpage2',vtDaUD.opD, 'Time Series Plots')

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%-------------------Data AnalysisGUI uiobject callbacks-----------%%%

    case 'dataTable_callback'
        [indices,data1,data2] = daTable_callback(vtDa.opD);
        vtDaUD.data1=data1;
        vtDaUD.data2=data2;
        dsingTseries(y1,y2)

    case 'taskpopMenu_callback'
        val = get (handles.taskpopMenu,'value');
        switch val
            case 1
                Rsq = datcorrCoef(vtDaUD.opD);
                tab1data = datWrappa(Rsq);%vtDaUD.wd
                set(handles.vtDaPanel1,...
                    'title', 'Table of Cross Correlations between Data');
            case 2
                [maxT,lags,coeff]= datCrossCorr(vtDaUD.opD,30);
                tab1data = datWrappa(maxT);%vtDaUD.wd
                set(handles.vtDaPanel1,...
                    'title', 'Table of Max Lag between Data');
        end
        set(handles.vtDaTable, 'data', tab1data.Data)%vtDaUD.wd.Data
        set(handles.vtDaTable2,'data', vtDaUD.feel.Data)
        set(handles.vtDaTable2,'columnname', vtDaUD.feel.Name)
        set(handles.vtDaTable2,'CellSelectionCallback',{@daTable2_callback,vtDaUD.opD});



    case 'pushTimeseries_callback'
        dsingTseries(vtDaUD.opD,vtDaUD.varName,vtDaUD.indices)

    case 'pushScatter_callback'
        dsingScatta(vtDaUD.opD,vtDaUD.varName,vtDaUD.indices)

    case 'pushMaxlag_callback'
        dsingMlags(vtDaUD.opD,vtDaUD.varName,vtDaUD.indices)


end
set(handles.dataAnalysisGUI,'UserData',vtDaUD)

我再次在控制器中拥有与我的数据对象一起操作的其他函数;对整件事真的很沮丧!如果我对问题的描述不够清楚,请告诉我,以便您可以提供帮助。谢谢

please am a student working on a project to develop a visualization tool to analyse data using an mvc design in matlab. but the problem im having is that im new to programming and matlab is the first real programing im doing. ive pretty much done the codes but i fear they are no way in an mvc design pattern so i need to change this.

would really appreciate as many imputes as possible to link me up with useful materials as i cant find any for mvc in matlab or may be exemplar codes that implement mvc in matlab to help give me an idea of how i can do mine, presently and doing things like this, where data is a structure with fileds for .Name and .Data. the functions/ methods datcorrCoef and datCorrSum are function i have created that accept my data object as arguments


function dataAnalysisGUI(data)

fdataAnalysisGUI = figure('Name','Data Analysis ',...
    'tag','dataAnalysisGUI',...
    'menu','none',...
    'units','normalized',...
    'NumberTitle', 'off')



%%% intialise the gui with data set to work with
vtDaUD.opD = data;



Rsq = datcorrCoef(vtDaUD.opD);
opit = datWrappa(Rsq);
vtDaUD.wd = opit;
vtDaUD.feel = datCorrSum(data);
%%%------------------- menus ------------------------------------------%%%
smh = uimenu('Label', 'Sort', 'Tag', 'daSortMenu');
cmh = uimenu(smh, 'Label', 'Sum of CorrCoeff ',...
    'Tag', 'correlation');
    uimenu(cmh, 'Label', 'Increasing ',...
    'Tag', 'cIncreasing',...
    'callback','vtDaCallbacks(''cIncreasing_callback'')');
    uimenu(cmh, 'Label', 'Decreasing ',...
    'Tag', 'cDecreasing',...
    'callback','vtDaCallbacks(''cDecreasing_callback'')');
mmh = uimenu(smh, 'Label', 'Max Lag ',...
    'Tag', 'maxLag');
    uimenu(mmh, 'Label', 'Increasing ',...
    'Tag', 'mIncreasing',...
    'callback','vtDaCallbacks(''mIncreasing_callback'')');
    uimenu(mmh, 'Label', 'Decreasing ',...
    'Tag', 'mDecreasing',...
    'callback','vtDaCallbacks(''mDecreasing_callback'')');



dmh = uimenu('Label', 'Display', 'Tag', 'daDisplayMenu');
            uimenu(dmh, 'Label', 'Scatter Plots ',...
                  'Tag', 'dScatter',...
                  'Callback','vtDaCallbacks(''dScatter_callback'')');
              uimenu(dmh, 'Label', 'Cross Correlation ',...
                  'Tag', 'dCrosscorr',...
                  'callback','vtDaCallbacks(''dCrosscorr_callback'')');
              uimenu(dmh, 'Label', 'Time Series ',...
                  'Tag', 'dTimeseries',...
                  'callback','vtDaCallbacks(''dTimeseries_callback'')');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%------------------------ panels ------------------------------------%%%
 vtDaPanel1 = uipanel(fdataAnalysisGUI,...
       'Units','normalized',...
       'Position', [.025 .035 .84 .95],...
       'FontSize',10,...
       'tag','vtDaPanel1',...
       'backgroundcolor',[0.8, 0.8,0.8],...
       'title', 'Table of Cross Correlations between Data');
    vtDaPanel2 = uipanel(fdataAnalysisGUI,...
       'Units','normalized',...
       'Position', [.87 .566 .12 .396],...
       'tag','vtDaPanel2',...
       'backgroundcolor',[0.8, 0.8,0.8],...
       'title', 'Analysis');

   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %%%------------------------- objects -------------------------------%%%
        uitable('parent', vtDaPanel1,...
            'tag','vtDaTable',...
            'RearrangeableColumn', 'on',...
            'clipping','off',...
            'Units','normalized',...
            'Position',[.01 .2 .98 .8],...
            'data',opit.Data,...
            'rowname',opit.Name,...
            'columnname',opit.Name,...
            'CellSelectionCallback',{@daTable_callback,vtDaUD.opD});

        uitable('parent', vtDaPanel1,...
            'tag','vtDaTable2',...
            'RearrangeableColumn', 'on',...
            'Units','normalized',...
            'Position',[.01 .01 .98 .15],...
            'data',vtDaUD.feel.Data,...
            'rowname','Sum of Corr. Coeff',...
            'columnname',vtDaUD.feel.Name,...
            'TooltipString','select column header to drill down',...
            'CellSelectionCallback',{@daTable2_callback,vtDaUD.opD});


        uicontrol(vtDaPanel2, 'Style', 'popupmenu',...
            'tag','taskpopMenu',...
            'Units','normalized',...
            'Position', [.10 .75 .8 .1],...
            'String', {'Correlation Coeff';'Max lags'},...
            'Callback', 'vtDaCallbacks(''taskpopMenu_callback'')');

        uicontrol(vtDaPanel2, 'Style', 'text',...
            'tag','staticTxt2',...
            'Units','normalized',...
            'Position', [.10 .86 .8 .05],...
            'String', {'Task'});

        uicontrol(vtDaPanel2, 'Style', 'text',...
            'tag','staticTxt3',...
            'Units','normalized',...
            'Position', [.10 .61 .8 .05],...
            'String', {'Mini Display'});

        uicontrol(vtDaPanel2, 'Style', 'pushbutton',...
            'tag','pushTimeseries',...
            'Units','normalized',...
            'Position', [.10 .5 .8 .1],...%[450 350 100 50]
            'String', {'TimeSeries'},...
            'Callback', 'vtDaCallbacks(''pushTimeseries_callback'')');

        uicontrol(vtDaPanel2, 'Style', 'pushbutton',...
            'tag','pushScatter',...
            'Units','normalized',...
            'Position', [.10 .35 .8 .1],...
            'String', {'Scatter'},...
            'Callback', 'vtDaCallbacks(''pushScatter_callback'')');

        uicontrol(vtDaPanel2, 'Style', 'pushbutton',...
            'tag','pushMaxlag',...
            'Units','normalized',...
            'Position', [.10 .2 .8 .1],...
            'String', {'Max Lag'},...
            'Callback', 'vtDaCallbacks(''pushMaxlag_callback'')');


name = genvarname(['daGUI' data.Name{2}]);%name = datname('daGUI',lenght(data.Name));
vtDaUD.varName = name;
eval([name '= data.Data']);
assignin('base',name,data.Data);


set(fdataAnalysisGUI,'UserData',vtDaUD)

and i have done the callback/ control as follows;

function vtDaCallbacks(action)
handles = guihandles(gcf);
vtDaUD = get(handles.dataAnalysisGUI,'UserData');
%tabdata=get(handles.vtDaTable,'data');
tab2Data.Data = get(handles.vtDaTable2,'data');
tab2Data.Name = get(handles.vtDaTable2,'columnname');


switch action
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%-----------------------Data AnalysisGUI menu callbacks-----------%%%
    case 'cIncreasing_callback'
        [newTabData,index] = sortaColumn(tab2Data,'ascend',1);
        vtDaUD.wd = dataselect(vtDaUD.opD,index);
        set(handles.vtDaTable2, 'data', newTabData.Data)
        set(handles.vtDaTable2, 'columnname', newTabData.Name)
        set(handles.vtDaTable2,'CellSelectionCallback',{@daTable2_callback,vtDaUD.wd});


    case 'cDecreasing_callback'
        [newTabData,index] = sortaColumn(tab2Data,'descend',1);
        vtDaUD.wd = dataselect(vtDaUD.opD,index);
        %[vtDaUD.wd,newTabData,newcolumnname] = sortta2(vtDaUD.opD,'descend',tab2Data,1);
        set(handles.vtDaTable2, 'data', newTabData.Data)
        set(handles.vtDaTable2, 'columnname', newTabData.Name)
        set(handles.vtDaTable2,'CellSelectionCallback',{@daTable2_callback,vtDaUD.wd});

    case 'dScatter_callback'
        dataDispGUI('dScatta','calnumpage2',vtDaUD.opD, 'Scatter Plots')

    case 'dTimeseries_callback'
        dataDispGUI('dTimeSeries2','calnumpage2',vtDaUD.opD, 'Time Series Plots')

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%-------------------Data AnalysisGUI uiobject callbacks-----------%%%

    case 'dataTable_callback'
        [indices,data1,data2] = daTable_callback(vtDa.opD);
        vtDaUD.data1=data1;
        vtDaUD.data2=data2;
        dsingTseries(y1,y2)

    case 'taskpopMenu_callback'
        val = get (handles.taskpopMenu,'value');
        switch val
            case 1
                Rsq = datcorrCoef(vtDaUD.opD);
                tab1data = datWrappa(Rsq);%vtDaUD.wd
                set(handles.vtDaPanel1,...
                    'title', 'Table of Cross Correlations between Data');
            case 2
                [maxT,lags,coeff]= datCrossCorr(vtDaUD.opD,30);
                tab1data = datWrappa(maxT);%vtDaUD.wd
                set(handles.vtDaPanel1,...
                    'title', 'Table of Max Lag between Data');
        end
        set(handles.vtDaTable, 'data', tab1data.Data)%vtDaUD.wd.Data
        set(handles.vtDaTable2,'data', vtDaUD.feel.Data)
        set(handles.vtDaTable2,'columnname', vtDaUD.feel.Name)
        set(handles.vtDaTable2,'CellSelectionCallback',{@daTable2_callback,vtDaUD.opD});



    case 'pushTimeseries_callback'
        dsingTseries(vtDaUD.opD,vtDaUD.varName,vtDaUD.indices)

    case 'pushScatter_callback'
        dsingScatta(vtDaUD.opD,vtDaUD.varName,vtDaUD.indices)

    case 'pushMaxlag_callback'
        dsingMlags(vtDaUD.opD,vtDaUD.varName,vtDaUD.indices)


end
set(handles.dataAnalysisGUI,'UserData',vtDaUD)

where i again have other functions that operate with my data object here in the controller; really frustrated about the whole thing!! please let me know if im not being clear enough about the description of my problem so you can please help out. thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谈场末日恋爱 2024-09-21 07:27:41

对于 MVC,您需要正确的面向对象。 MATLAB 中的 OO 在较新的版本中可用,您可以像在 Java 中执行 MVC 一样执行此操作。但它在 MATLAB 中“感觉”不太对(所以我认为你的老师不是这个意思),因为在大多数简单的情况下以及对于复杂/大型 UI 的 MATLAB 速度太慢,并且在某些情况下存在性能问题。

否则,您可以使用嵌套函数(CS 中的闭包)。通过闭包,可以“模拟”一些面向对象的功能。唯一的问题是所有内容都必须保留在一个 m 文件中。

  • 模型:嵌套范围变量(此处名为“this”)
  • 视图:uicontrols(和其他 ui 元素)
  • 控制器:回调

这是一个非常基本的示例,只需用模型数据填充它并查看 ui 的:

    function mvc_test()

    //% THIS is nested scope variable
    this.model = getModel(); 
    this.view = getView();

    //% create model
    function model = getModel()
        model.data1 = 1;
    end

    //% create view
    function view = getView()
        view.hfig = figure();
        view.hbtn = uicontrol( 'style', 'push', 'string', 'click me', 'callback', @btn1_cb );
    end

    //% controller
    function btn1_cb(varargin)
        this.model.data1 = this.model.data1 + 1;
        set( this.view.hbtn, 'string', num2str(this.model.data1) );
    end
    end

For MVC you need proper Object-Orientation. OO in MATLAB is available in the newer versions, you can just do it like you would do MVC in Java. But it does not "feel" right in MATLAB (so I do not think your instructor meant this) because it would be an overkill in most simple cases and for complex/large UI's MATLAB is too slow and has performance issues in some scenarios.

Otherwise you can use nested functions (closures in CS). With closures some OO functionality can be "emulated". The only problem is that everything has to stay in one m-file.

  • Model: nested scope variable (here named "this")
  • View: uicontrols (and other ui elements)
  • Controller: callbacks

Here is a very basic example, just fill it with your model data and view ui's:

    function mvc_test()

    //% THIS is nested scope variable
    this.model = getModel(); 
    this.view = getView();

    //% create model
    function model = getModel()
        model.data1 = 1;
    end

    //% create view
    function view = getView()
        view.hfig = figure();
        view.hbtn = uicontrol( 'style', 'push', 'string', 'click me', 'callback', @btn1_cb );
    end

    //% controller
    function btn1_cb(varargin)
        this.model.data1 = this.model.data1 + 1;
        set( this.view.hbtn, 'string', num2str(this.model.data1) );
    end
    end
过期以后 2024-09-21 07:27:41

你正在尝试的是一件不平凡的事情。 MATLAB 的 UI 系统 GUIDE 并不是那么灵活。我讨厌对此持消极态度。我很欣赏您尝试按照某种模式开发 UI,但我只想使用 GUIDE 并保留自动生成的代码段。

使用 Java 或 C# 作为 UI,然后使用 MATLAB Builder NEMATLAB Builder Java 引入 MATLAB 来进行繁重的处理是一个更好的选择。我不确定学生版是否附带此功能,但这确实是您想要的。

任何程序员都会学到的最重要的教训之一是每种语言都有优点和缺点。试图将一种语言强行纳入其设计目的之外的范式是一场艰苦的战斗,通常会以哭泣而不是欢欣告终。

What you are attempting is a non-trivial thing. MATLAB's UI system, GUIDE, is not really that flexible. I hate to be negative about this. I appreciate that you are attempting to develop a UI following a pattern, but I would simply use GUIDE and stay with the auto generated code segments.

Using Java or C# for the UI and then using MATLAB Builder NE or MATLAB Builder Java to bring in MATLAB for the heavy lifting of processing is a much better option. I am not sure the student version comes with that, but that is really what you want.

One of the most important lessons any programmer will learn is that each language has strengths and weaknesses. Trying to force a language into a paradigm it was not designed to be used for is an up hill battle, that will usually end with more crying then rejoicing.

猥︴琐丶欲为 2024-09-21 07:27:41

我刚刚研究了在 Matlab 中进行 MVC,并提出了一种模式,我认为考虑到 Matlab 的局限性,这种模式是可行的。主要问题是 GUI 文件是图形对象句柄而不是类。但是,如果将 GUI 包装在视图类中,则可以订阅模型类中的可观察属性。您必须放弃使用 GUI 中的句柄结构来存储所有用户数据……这与设计模式不符。好消息是 Matlab 类很好地支持事件和侦听器,包括我提到的可观察属性。

我的解决方案的演示可以在 Matlab Central File Exchange 上找到,网址为 http://www.mathworks.com/matlabcentral/fileexchange/40294-model-view-control-pattern-using-guide
有关实现的更详细描述,请参阅博客文章 http:// myunscriptedblog.blogspot.com/2013/02/mvc-in-matlab.html

I have just looked at doing MVC in Matlab and have come up with a pattern I think works will given the limitations of Matlab. The main problem is that GUI files are graphics object handles and not classes. However, if you wrap the GUI in a view class, you can subscribe to observable properties in a model class. You have to let go of using the handles structure in the GUI to store all your user data...that doesn't jive with the design pattern. The good news is that Matlab classes support events and listeners quite well, including the observable properties I alluded to.

The demo of my solution can be found on the Matlab Central File Exchange at http://www.mathworks.com/matlabcentral/fileexchange/40294-model-view-control-pattern-using-guide.
A more detailed description of the implementation is in a blog post at http://myunscriptedblog.blogspot.com/2013/02/mvc-in-matlab.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文