首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将GUI数据从matlab中保存到三维矩阵中

将GUI数据从matlab中保存到三维矩阵中
EN

Stack Overflow用户
提问于 2013-11-29 16:03:08
回答 1查看 264关注 0票数 0

我想保存矩阵,这是通过图形用户界面按钮输入到一个3D矩阵。例如:我单击按钮1,将2-2矩阵放在3D矩阵的第一个切片中。我比点击按钮3和一个不同的2-2矩阵是放在第二片.就这样等等。我希望这是足够清楚的。我的问题是我不是一个有经验的程序员。我目前初始化了一个零矩阵,如下所示:

代码语言:javascript
复制
storageMatrix  = ones(2,2,100);
setappdata(0, 'storageMatrix', storageMatrix);

我已经在主脚本中添加了一个函数updateStorageMatrix,请注意,这还没有完成。

代码语言:javascript
复制
function updateStorageMatrix

storageMatrix = getappdata(0, 'storageMatrix');

例如,当我查看按钮1的代码时,它看起来是这样的:

代码语言:javascript
复制
% --- Executes on button press in Add_Straightduct.
function Add_Straightduct_Callback(hObject, eventdata, handles)
%prompt command for k number and length
    prompt       = {'k0:','Length:'};
    dlg_title    = 'Straight Duct specs';
    num_lines    = 1;
    SDelements   = {'0','0'};
    Straightduct = inputdlg(prompt,dlg_title,num_lines,SDelements)

%insert values in function
    sizeStorageMatrix = size(getappdata(0,'storageMatrix'));      %get size of the storage matrix

    dimT              = sizeStorageMatrix(1,3);   %take the number of matrices

        if dimT==1

            straightDuct = straight_duct(str2num(SDelements{1}), str2num(SDelements{2}), Mach_Frange(1,1))

            setappdata(handles.updateStorageMatrix,'storageMatrix', storageMatrix(1:2, 1:2, 1))=straight_duct(str2num(SDelements{1}), str2num(answer{2}), Mach_Frange(1,1))

            dimT+1

        else 
            setappdata(0,'storageMatrix', storageMatrix(1:2, 1:2, dimT+1))=straight_duct(str2num(SDelements{1}), str2num(answer{2}), Mach_Frange(1,1))
            dimT+1
        end

straight_duct()是我在脚本中计算消音器时使用的函数,我有几个函数,我不确定这是否是使用GUI时的工作方式。我只希望你了解我想要达到的目标,并在路上帮助我。因此,我实际上可以为我的脚本创建一个UI :)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-29 18:09:37

这假设您已经在GUI的其他地方初始化了storageMatrix,如下所示.

代码语言:javascript
复制
handles.storageMatrix = zeros(2,2,100);
guidata(hObject,handles); % Must call this to save handles so other callbacks can access the new element "storageMatrix"

然后在你的第一个按钮的回调..。

代码语言:javascript
复制
% --- Executes on button press in Add_Straightduct.
function Add_Straightduct_Callback(hObject, eventdata, handles)
.
. % Whatever initializations you need to do
.

localStorageMatrix = handles.storageMatrix;  %load the storageMatrix being used by other callbacks/functions

.
. % Whatever you need to do to generate the new 2x2 matrix "slice"
.

localStorageMatrix(:,:,end+1) = newSlice; % appends the new slice to the end of the, indexing using colons assumes newSlice is of the same first and second dimension as other slices in localStorageMatrix
handles.storageMatrix = localStorageMatrix; % overwrite the storageMatrix in handles with the contents of the new localStorageMatrix
guidata(hObject,handles); % save the handles struct again now that you've changed it

或者,您可以在整个过程中只使用handles.storageMatrix,而不包括localStorageMatrix,但我已经将它包括进来作为重点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20289568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档