简体   繁体   English

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

[英]How to pass data from one GUI to an other? Matlab

I am using a sub GUI to open the main GUI. 我正在使用子GUI打开主GUI。 In the sub GUI a pushbutton aLLows the user to select the data files they would like to upload. 在子GUI中,一个按钮允许用户选择他们想要上传的数据文件。 The first file is dealt with seperately and is then passed to the main GUI using setappdata and getappdata . 第一个文件被单独处理,然后使用setappdatagetappdata传递到主GUI。 Here is the code for the push button in the sub 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

Then when I push a button in the main GUI i should get the data sent from the sub to preform calculations on this data. 然后,当我按下主GUI中的按钮时,我应该获取从子模块发送来的数据,以便对该数据进行预计算。 Here is the code: 这是代码:

% --- 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')

But when I push this button in the main GUI i get the errors: 但是,当我在主GUI中按此按钮时,出现错误:

Reference to non-existent field 'ManualMultiple'.

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

Can anyone tell me how I could resolve this problem or even help me see where I am going wrong? 谁能告诉我如何解决这个问题,甚至可以帮助我了解问题出在哪里? Thanks in advance 提前致谢

What if you add guidata(hObject,handles) after this line: 如果在此行之后添加guidata(hObject,handles)怎么办:

setappdata(handles.ManualMultiple,'Data',DataUseLater) in your main window? setappdata(handles.ManualMultiple,'Data',DataUseLater)在您的主窗口中吗? It looks as if the handles structure was not updated after you created handles.ManualMultiple 创建句柄后,似乎句柄结构未更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM