如何将数据从一个GUI传递到另一个GUI? MATLAB

时间:2014-06-13 14:01:12

标签: matlab user-interface

我正在使用子GUI打开主GUI。在子GUI中,按钮aLLows允许用户选择他们想要上传的数据文件。第一个文件单独处理,然后使用setappdatagetappdata传递到主GUI。以下是子GUI中按钮的代码:

% --- Executes on button press in ManualMultiple.
function ManualMultiple_Callback(hObject, eventdata, handles)
% hObject    handle to ManualMultiple (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FileName,PathName,FilterIndex] = uigetfile('*.txt*','MultiSelect','on');
numfiles = size(FileName,2);
    setappdata(0,'files',numfiles)
FileData= cell(1,numfiles);
for ii = 1:numfiles
    FileName{ii};
    A=[];
    entirefile =fullfile(PathName,FileName{ii});
    fid = fopen(entirefile);
    tline = fgets(fid);
    while ischar(tline)
        parts = textscan(tline, '%f;');
        if numel(parts{1}) > 0
            A = [ A ; parts{:}' ];
        end
        tline = fgets(fid);
    end
    fclose(fid);
    FileData{ii} = A;

    A = FileData{ii};
    X1 = A(:,1);
    Y1 = A(:,5);
   DataToUse{ii} = [X1, Y1];
end

    FirstLoopX1Y1 = DataToUse{1};

    X = FirstLoopX1Y1(:,1);
    Y = FirstLoopX1Y1(:,2);
     setappdata(0,'XValue',X)
     setappdata(0,'YValue',Y)

    for i = 2:numfiles   
       OtherLoopsXY = DataToUse{i};
        X3 = OtherLoopsXY(:,1);
        Y3 = OtherLoopsXY(:,2);
        DataUseLater{i} = [X3,Y3]
    end
   setappdata(handles.ManualMultiple,'Data',DataUseLater)

GUImainwindow

然后,当我按下主GUI中的按钮时,我应该从子数据发送数据到预先形成的数据计算。这是代码:

% --- Executes on button press in CalculateIntensity.
function CalculateIntensity_Callback(hObject, eventdata, handles)
% hObject    handle to CalculateIntensity (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Trapz function
starting_value = getappdata(0,'StartValue');
ending_value = getappdata(0,'EndValue');
StartingValue = str2num(starting_value);
EndingValue = str2num(ending_value);

A = getappdata(0,'XYarray');
 %line 122 and 123 finds location of data in the entire spectrum
[~,indx1]=ismember(StartingValue,A,'rows');
[~,indx2]=ismember(EndingValue,A,'rows');
arrayfortrapz = A(indx1:indx2,1:2);
setappdata(0,'arraytapz',arrayfortrapz);
[value,index] = max(arrayfortrapz(:,2)); %finds max intensity / peak value
PeakValue = arrayfortrapz(index,1);
handles.Peak_Value = PeakValue;
guidata(hObject,handles);

X1 = arrayfortrapz(1:end,1);
Y1 = arrayfortrapz(1:end,2);
 AUC = trapz(X1,Y1); %intergration
 str = num2str(AUC);
 [s,v] = listdlg('PromptString','Calculated Intensity:','SelectionMode','single','ListString',str,'ListSize',[200 200]);
 IntensityValue = str(s,:);
 setappdata(0,'IV',IntensityValue);

 DataUseLater = getappdata(handles.ManualMultiple,'Data')

但是当我在主GUI中按下此按钮时,我得到错误:

Reference to non-existent field 'ManualMultiple'.

Error in MichelleLaycockGUImainwindow>CalculateIntensity_Callback (line 207)
 DataUseLater = getappdata(handles.ManualMultiple,'Data')

有谁能告诉我如何解决这个问题甚至帮助我看看我哪里出错了?提前致谢

1 个答案:

答案 0 :(得分:0)

如果在此行之后添加guidata(hObject,handles),该怎么办:

主窗口中的

setappdata(handles.ManualMultiple,'Data',DataUseLater)?在创建handle.ManualMultiple

之后,看起来好像没有更新句柄结构