Verfasst am: 08.07.2015, 16:39
Titel: Matrix in GUI-Tabelle schreiben
Hallo,
ich denke mir, dass das eine doofe Frage ist, aber ich stehe gerade einfach auf dem Schlauch:
Ich habe mein erstes GUI erstellt und habe auch schon relativ viel eingebunden etc.
Jetzt wollte ich eine kleine Erweiterung:
Ich erstelle im Laufe meines Programmes eine Matrix. Diese wird zum einen in ene Excel-Tabelle gespeichert ( das läuft ohne Problem ), zum anderen hätte ich sie aber am ende des Programmes ebenfalls noch in einer Tabelle im GUI angezeigt.
Der interessante Teil meines bisherigen Codes:
Form der Tabelle/Matrix ist einfach eine 3x3 Matrix
Code:
% --- Executes when entered data in editable cell(s) in uitable1. function uitable1_CellEditCallback(hObject, eventdata, handles) % hObject handle to uitable1 (see GCBO) % eventdata structure with the following fields (see UITABLE1) % Indices: row and column indices of the cell(s) edited % PreviousData: previous data for the cell(s) edited % EditData: string(s) entered by the user % NewData: EditData or its converted form set on the Data property. Empty if Data was not changed % Error: error string when failed to convert EditData to appropriate value for Data % handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties. function uitable1_CreateFcn(hObject, eventdata, handles) % hObject handle to uitable1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in start_programm. function start_programm_Callback(hObject, eventdata, handles) % hObject handle to start_programm (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
ok, ich dachte, dass es vielleicht an der Tabellenfunktion liegt, also habe ich mir eine eigene kleine Tabelle aus "Edit-Fenstern" gebastelt.
Jetzt funktioniert gar nichts mehr.
Ich habe in anderen Forenbeiträgen gelesen, dass meine Fehlermeldung ein Zeichen dafür ist, dass mein handle nicht existiert.
Langsam bin ich echt am verzweifeln und vorallem dabei an mir zu zweifeln.
Es ist etwas viel, aber es folgt der komplette code meines GUI:
(entschuldigung dafür...)
Code:
functionvarargout = AVES(varargin) % AVES MATLAB code for AVES.fig % AVES, by itself, creates a new AVES or raises the existing % singleton*.
%
% H = AVES returns the handle to a new AVES or the handle to % the existing singleton*.
%
% AVES('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in AVES.M with the given input arguments.
%
% AVES('Property','Value',...) creates a new AVES or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before AVES_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to AVES_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help AVES
% Last Modified by GUIDE v2.5 09-Jul-2015 14:41:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @AVES_OpeningFcn, ...
'gui_OutputFcn', @AVES_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before AVES is made visible. function AVES_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to AVES (see VARARGIN)
% Choose default command line output for AVES
handles.output = hObject;
% UIWAIT makes AVES wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = AVES_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
function set_title_Callback(hObject, eventdata, handles) % hObject handle to set_title (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of set_title as text % str2double(get(hObject,'String')) returns contents of set_title as a double
% --- Executes during object creation, after setting all properties. function set_title_CreateFcn(hObject, eventdata, handles) % hObject handle to set_title (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function set_input_location_Callback(hObject, eventdata, handles) % hObject handle to set_input_location (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of set_input_location as text % str2double(get(hObject,'String')) returns contents of set_input_location as a double
% --- Executes during object creation, after setting all properties. function set_input_location_CreateFcn(hObject, eventdata, handles) % hObject handle to set_input_location (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function location_excel_table_Callback(hObject, eventdata, handles) % hObject handle to location_excel_table (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of location_excel_table as text % str2double(get(hObject,'String')) returns contents of location_excel_table as a double
% --- Executes during object creation, after setting all properties. function location_excel_table_CreateFcn(hObject, eventdata, handles) % hObject handle to location_excel_table (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in browse_input_files. function browse_input_files_Callback(hObject, eventdata, handles) % hObject handle to browse_input_files (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename1,pathname1]=uigetfile({'*.mat'},'location of input files');
% pathname2=cell(1); % pathname2{1}=pathname1; % um späteren Fehler zu verhindern set(handles.set_input_location,'String',pathname1);
function total_r_Callback(hObject, eventdata, handles) % hObject handle to total_r (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of total_r as text % str2double(get(hObject,'String')) returns contents of total_r as a double
% --- Executes during object creation, after setting all properties. function total_r_CreateFcn(hObject, eventdata, handles) % hObject handle to total_r (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function total_l_Callback(hObject, eventdata, handles) % hObject handle to total_l (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of total_l as text % str2double(get(hObject,'String')) returns contents of total_l as a double
% --- Executes during object creation, after setting all properties. function total_l_CreateFcn(hObject, eventdata, handles) % hObject handle to total_l (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function total_TO_Callback(hObject, eventdata, handles) % hObject handle to total_TO (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of total_TO as text % str2double(get(hObject,'String')) returns contents of total_TO as a double
% --- Executes during object creation, after setting all properties. function total_TO_CreateFcn(hObject, eventdata, handles) % hObject handle to total_TO (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function truck_r_Callback(hObject, eventdata, handles) % hObject handle to truck_r (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of truck_r as text % str2double(get(hObject,'String')) returns contents of truck_r as a double
% --- Executes during object creation, after setting all properties. function truck_r_CreateFcn(hObject, eventdata, handles) % hObject handle to truck_r (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function truck_l_Callback(hObject, eventdata, handles) % hObject handle to truck_l (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of truck_l as text % str2double(get(hObject,'String')) returns contents of truck_l as a double
% --- Executes during object creation, after setting all properties. function truck_l_CreateFcn(hObject, eventdata, handles) % hObject handle to truck_l (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function truck_TO_Callback(hObject, eventdata, handles) % hObject handle to truck_TO (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of truck_TO as text % str2double(get(hObject,'String')) returns contents of truck_TO as a double
% --- Executes during object creation, after setting all properties. function truck_TO_CreateFcn(hObject, eventdata, handles) % hObject handle to truck_TO (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function other_r_Callback(hObject, eventdata, handles) % hObject handle to other_r (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of other_r as text % str2double(get(hObject,'String')) returns contents of other_r as a double
% --- Executes during object creation, after setting all properties. function other_r_CreateFcn(hObject, eventdata, handles) % hObject handle to other_r (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function other_l_Callback(hObject, eventdata, handles) % hObject handle to other_l (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of other_l as text % str2double(get(hObject,'String')) returns contents of other_l as a double
% --- Executes during object creation, after setting all properties. function other_l_CreateFcn(hObject, eventdata, handles) % hObject handle to other_l (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function other_TO_Callback(hObject, eventdata, handles) % hObject handle to other_TO (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of other_TO as text % str2double(get(hObject,'String')) returns contents of other_TO as a double
% --- Executes during object creation, after setting all properties. function other_TO_CreateFcn(hObject, eventdata, handles) % hObject handle to other_TO (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in browse_excel. function browse_excel_Callback(hObject, eventdata, handles) % hObject handle to browse_excel (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename_a,pathname_a]=uigetfile({'\\*.*'},'location of excel-table');
pathname_b=cell(1);
path=strcat(pathname_a,filename_a);
% pathname_b{1}=path; set(handles.location_excel_table,'String',path);
% --- Executes on button press in start_programm. function start_programm_Callback(hObject, eventdata, handles) % hObject handle to start_programm (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % assignin('base', 'Titel',get(handles.set_title,'String'));
Titel = get(handles.set_title,'String');
input_file_location = get(handles.set_input_location, 'String');
excel_location = get(handles.location_excel_table, 'String');
tabelle=start_count_and_plot(Titel, input_file_location, excel_location, handles.axes2);
disp(tabelle);
Die Tabelle ist immernoch eine 3x3 Matrix, aber die kann ich ja mit dem jeweiligen Index ganz gut ansprechen.
Die Ausgabe in GUI sieht folgendermaßen aus:
| |total|truck|other|
|right|...|...|...|
|left |...|...|...|
|middle|...|...|...|
und ich bekomme immernoch Error using handle.handle/set
kann jemand sehen wo ich meine handle lösche?!
ich habe in der funktion "start_count_and_plot" kein clear all oder sowas..
_________________
Der Wert von handles in den Input-Argumenten des Callbacks entspricht dem Wert während der Definition des Callbacks.
ich verstehe nicht ganz was du meinst, bin noch frisch im Matlab-Land
muss ich die codezeile in der callback-funktion meines edit-blockes oder in der start_programm_callback schreiben?
und zur Ausgabe in GUI:
ich wollte anfangs eine Tabelle 3x3, das hat aber nicht funktioniert. also habe ich mir einfach 3x3 edit-blöcke genommen. Ich dachte das wäre einfacher, immerhin schreibe ich in andere edit-blöcke (z.B set_excel_location block) ja auch einfach rein. Und das jeweils über set(). Deswegen versteh ich ja erst recht nicht, wieso es jetzt nicht mehr funktioniert. Ich habe ja nichts geändert..
Aber jetzt schon einmal vielen Dank für die Rückmeldung, hat mir wenigstens ein wenig Mut gegeben!
_________________
never touch a running system!
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.