我是一名学生,正在开发一个使用MVC设计在Matlab中分析数据的可视化工具项目。但我遇到的问题是我对编程和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)
在这里,我又有其他与我的数据对象一起操作的函数;整件事情让我非常沮丧!!如果我对问题的描述不够清晰,请告诉我,以便您可以帮助解决。谢谢