AppDesigner variable Table content
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I'm currently working on my first GUI in AppDesigner. In this GUI, I want to have a table with 2 columns, but with a variable number of rows. This number of rows is determined by the variable ws.mw.numHead. The variable is a string with the following content: "Head1; Head2; Head3; Head4; Head5;"
Is it incorrect to use a string for this purpose, and should I use the count instead? Or is there another mistake I'm making?
classdef gui_Rakes_Kopfauswahl < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
KompelierenLamp matlab.ui.control.Lamp
KompelierenLampLabel matlab.ui.control.Label
AuswertungLamp matlab.ui.control.Lamp
AuswertungLampLabel matlab.ui.control.Label
Tabelle matlab.ui.control.Table
AuswertenButton matlab.ui.control.Button
KopfauswahlLabel matlab.ui.control.Label
end
% Callbacks for app components
methods (Access = private)
getws;
% Code, der bei Start der App ausgeführt wird
function startupFcn(app)
% Überschrift setzen
app.KopfauswahlLabel.FontSize = 18;
app.KopfauswahlLabel.FontWeight = 'bold';
% Tabelle erstellen
numHeads = ws.mw.numHead;
numHeads = strsplit(numHeads, ';');
numHeads = strtrim(numHeads);
numHeads = numHeads(~cellfun('isempty', numHeads));
numRows = numel(numHeads)
data = cell(numRows, 2);
for i = 1:numRows
data{i, 1} = sprintf('Kopf %d', i);
data{i, 2} = '3 Lochsonde'; % Standard-Auswerteverfahren
end
% Auswerteverfahren definieren
auswerteverfahren = {'3 Lochsonde', '4 Lochsonde', '5 Lochsonde', '9 Lochsonde', 'Temperatur Sonde', 'Totaldrucksonde', 'Recovery Faktor'};
% Tabelle erstellen und Auswerteverfahren hinzufügen
app.Tabelle.Data = data;
app.Tabelle.ColumnName = {'Kopf', 'Auswerteverfahren'};
app.Tabelle.ColumnEditable = [false, true];
app.Tabelle.ColumnFormat = {'char', auswerteverfahren};
% Auswerten-Button Callback-Funktion definieren
app.AuswertenButton.ButtonPushedFcn = @(~,~) auswertenButtonPushed(app);
end
% Callback-Funktion für den Auswerten-Button
function auswertenButtonPushed(app)
% Daten aus der Tabelle abrufen
data = app.Tabelle.Data;
% Überprüfen, ob jedem Kopf ein Auswerteverfahren zugewiesen wurde
missingAssignments = find(strcmp(data(:, 2), '3 Lochsonde'));
if ~isempty(missingAssignments)
errorMessage = sprintf('Zuordnung fehlt für Kopf %d', missingAssignments(1));
errordlg(errorMessage, 'Fehler', 'modal');
return;
end
% Auswertungen für jeden Kopf durchführen
for i = 1:size(data, 1)
auswerteverfahren = app.Tabelle.Data{i, 2};
switch auswerteverfahren
case '3 Lochsonde'
% Auswertung für 3 Lochsonde
fuehreAuswertungDurch
fprintf('Auswertung für Kopf %d: 3 Lochsonde\n', i);
fuehreExportDurch
case '4 Lochsonde'
% Auswertung für 4 Lochsonde
fuehreAuswertungDurch
fprintf('Auswertung für Kopf %d: 4 Lochsonde\n', i);
fuehreExportDurch
case '5 Lochsonde'
% Auswertung für 5 Lochsonde
fuehreAuswertungDurch
fprintf('Auswertung für Kopf %d: 5 Lochsonde\n', i);
fuehreExportDurch
case '9 Lochsonde'
% Auswertung für 9 Lochsonde
fuehreAuswertungDurch
fprintf('Auswertung für Kopf %d: 9 Lochsonde\n', i);
fuehreExportDurch
case 'Temperatur Sonde'
fuehreAuswertungDurch
% Auswertung für Temperatur Sonde
fprintf('Auswertung für Kopf %d: Temperatur Sonde\n', i);
fuehreExportDurch
case 'Totaldrucksonde'
% Auswertung für Totaldrucksonde
Totaldruck_Auswertung
fprintf('Auswertung für Kopf %d: Totaldrucksonde\n', i);
Totaldruck_fuehreExportDurch;
case 'Recovery Faktor'
% Auswertung für Recovery Faktor
RecoveryFactor_Auswertung
fprintf('Auswertung für Kopf %d: Recovery Faktor\n', i)
RF_fuehreExportdurch;
end
end
end
end
% %Wenn der scheiß läuft...
% %GaLiGrü
% %Lukas
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create KopfauswahlLabel
app.KopfauswahlLabel = uilabel(app.UIFigure);
app.KopfauswahlLabel.FontSize = 20;
app.KopfauswahlLabel.FontWeight = 'bold';
app.KopfauswahlLabel.Position = [256 429 130 24];
app.KopfauswahlLabel.Text = 'Kopfauswahl';
% Create AuswertenButton
app.AuswertenButton = uibutton(app.UIFigure, 'push');
app.AuswertenButton.Position = [271 70 100 22];
app.AuswertenButton.Text = {'Auswerten'; ''};
% Create Tabelle
app.Tabelle = uitable(app.UIFigure);
app.Tabelle.ColumnName = {'Kopfauswahl'; 'Auswerteverfahren'};
app.Tabelle.RowName = {};
app.Tabelle.Position = [141 125 360 232];
% Create AuswertungLampLabel
app.AuswertungLampLabel = uilabel(app.UIFigure);
app.AuswertungLampLabel.HorizontalAlignment = 'right';
app.AuswertungLampLabel.Position = [168 380 69 22];
app.AuswertungLampLabel.Text = 'Auswertung';
% Create AuswertungLamp
app.AuswertungLamp = uilamp(app.UIFigure);
app.AuswertungLamp.Position = [252 380 20 20];
% Create KompelierenLampLabel
app.KompelierenLampLabel = uilabel(app.UIFigure);
app.KompelierenLampLabel.HorizontalAlignment = 'right';
app.KompelierenLampLabel.Position = [370 381 73 22];
app.KompelierenLampLabel.Text = 'Kompelieren';
% Create KompelierenLamp
app.KompelierenLamp = uilamp(app.UIFigure);
app.KompelierenLamp.Position = [458 381 20 20];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = gui_Rakes_Kopfauswahl
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
0 Commenti
Risposte (1)
Harald
il 14 Lug 2023
Hi Lukas,
please consider providing the app as a file. This makes it easier to run and inspect it.
If you have an indication that you are making a mistake, such as an error message, please post that error message.
I suspect that ws.mw.numHead cannot be found as startupFcn has its own workspace and I don't see how ws would make it into this workspace. Please see here for information on how to pass inputs to an app:
If you are at a university that has a campus-wide license, you have access to a variety of self-paced trainings at no extra cost:
This may help get a better understanding of functions and workspaces.
All "onramps" are free for everybody.
Best wishes,
Harald
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!