How to solve startupFcn issue?
12 次查看(过去 30 天)
显示 更早的评论
Warid Islam
2019-6-11
I have been trying to use the App Designer feature in Matlab. A portion of my code is below:
% Code that executes after component creation
function startupFcn(app, varargin)
% Configure image axes
app.ImageAxes.Visible = 'off';
app.ImageAxes.Colormap = gray(256);
axis(app.ImageAxes, 'image');
% Construct app
function app = Patient(varargin)
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
if nargout == 0
clear app
end
end
Despite running the code multiple times, I get the above error message repeatedly. Any help would be appreciated. Thank you.
2 个评论
Warid Islam
2019-6-11
classdef Patient < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ImageAxes_2 matlab.ui.control.UIAxes
BrainViewButton matlab.ui.control.Button
BloodViewButton matlab.ui.control.Button
VentriclesViewButton matlab.ui.control.Button
TissueViewButton matlab.ui.control.Button
InfoPanel matlab.ui.container.Panel
PatientNameLabel_2 matlab.ui.control.Label
PatientNameEditField matlab.ui.control.EditField
OptionPanel matlab.ui.container.Panel
OpenButton matlab.ui.control.Button
FlipButton matlab.ui.control.Button
RunButton matlab.ui.control.Button
EditingPanel matlab.ui.container.Panel
CorrectionButton matlab.ui.control.Button
CleaningToolForBloodButton matlab.ui.control.Button
CleaningToolforVentriclesButton matlab.ui.control.Button
CleaningToolforCalcificationButton matlab.ui.control.Button
MorphologicalOperationsButton matlab.ui.control.Button
UndoButton matlab.ui.control.Button
BloodToolButton matlab.ui.control.Button
DeleteButton matlab.ui.control.Button
AnalyzePanel matlab.ui.container.Panel
CreateBoundaryButton matlab.ui.control.Button
SAHButton matlab.ui.control.Button
ICHButton matlab.ui.control.Button
SDHButton matlab.ui.control.Button
IVHButton matlab.ui.control.Button
DataPanel matlab.ui.container.Panel
AddExplanationButton matlab.ui.control.Button
ExportDataButton matlab.ui.control.Button
OpenResultsButton matlab.ui.control.Button
StartBrainSliceButton matlab.ui.control.Button
EditField matlab.ui.control.EditField
FullBrainSliceButton matlab.ui.control.Button
EditField_2 matlab.ui.control.EditField
ComputationPanel matlab.ui.container.Panel
AllSlicesPanel matlab.ui.container.Panel
BrainVolumeEditFieldLabel matlab.ui.control.Label
BrainVolumeEditField matlab.ui.control.EditField
BloodVolumeEditFieldLabel matlab.ui.control.Label
BloodVolumeEditField matlab.ui.control.EditField
VentriclesVolumeEditFieldLabel matlab.ui.control.Label
VentriclesVolumeEditField matlab.ui.control.EditField
TissueVolumeEditFieldLabel matlab.ui.control.Label
TissueVolumeEditField matlab.ui.control.EditField
BloodStatsPanel matlab.ui.container.Panel
SAHEditFieldLabel matlab.ui.control.Label
SAHEditField matlab.ui.control.EditField
ICHEditFieldLabel matlab.ui.control.Label
ICHEditField matlab.ui.control.EditField
SDHEditFieldLabel matlab.ui.control.Label
SDHEditField matlab.ui.control.EditField
IVHEditFieldLabel matlab.ui.control.Label
IVHEditField matlab.ui.control.EditField
CurrentSlicePanel matlab.ui.container.Panel
BloodStatsPanel_2 matlab.ui.container.Panel
SAHEditField_2Label matlab.ui.control.Label
SAHEditField_2 matlab.ui.control.EditField
ICHEditField_2Label matlab.ui.control.Label
ICHEditField_2 matlab.ui.control.EditField
SDHEditField_2Label matlab.ui.control.Label
SDHEditField_2 matlab.ui.control.EditField
IVHLabel matlab.ui.control.Label
IVHEditField_2 matlab.ui.control.EditField
EditField_9 matlab.ui.control.EditField
EditField_10 matlab.ui.control.EditField
EditField_11 matlab.ui.control.EditField
EditField_12 matlab.ui.control.EditField
CreateBoundaryStatsPanel matlab.ui.container.Panel
EditField_3 matlab.ui.control.EditField
EditField_4 matlab.ui.control.EditField
EditField_5 matlab.ui.control.EditField
EditField_6 matlab.ui.control.EditField
BrainDemoLabel matlab.ui.control.Label
ImageAxes_3 matlab.ui.control.UIAxes
end
function updateimage(app,imagefile)
% For corn.tif, read the second image in the file
if strcmp(imagefile,'corn.tif')
im = imread('corn.tif', 2);
else
try
im = imread(imagefile);
catch ME
% If problem reading image, display error message
uialert(app.UIFigure, ME.message, 'Image Error');
return;
end
end
% Create histograms based on number of color channels
switch size(im,3)
case 1
% Display the grayscale image
imagesc(app.ImageAxes,im);
% Plot all histograms with the same data for grayscale
histr = histogram(app.RedAxes, im, 'FaceColor',[1 0 0],'EdgeColor', 'none');
histg = histogram(app.GreenAxes, im, 'FaceColor',[0 1 0],'EdgeColor', 'none');
histb = histogram(app.BlueAxes, im, 'FaceColor',[0 0 1],'EdgeColor', 'none');
case 3
% Display the truecolor image
imagesc(app.ImageAxes,im);
% Plot the histograms
histr = histogram(app.RedAxes, im(:,:,1), 'FaceColor', [1 0 0], 'EdgeColor', 'none');
histg = histogram(app.GreenAxes, im(:,:,2), 'FaceColor', [0 1 0], 'EdgeColor', 'none');
histb = histogram(app.BlueAxes, im(:,:,3), 'FaceColor', [0 0 1], 'EdgeColor', 'none');
otherwise
% Error when image is not grayscale or truecolor
uialert(app.UIFigure, 'Image must be grayscale or truecolor.', 'Image Error');
return;
end
% Get largest bin count
maxr = max(histr.BinCounts);
maxg = max(histg.BinCounts);
maxb = max(histb.BinCounts);
maxcount = max([maxr maxg maxb]);
% Set y axes limits based on largest bin count
app.RedAxes.YLim = [0 maxcount];
app.RedAxes.YTick = round([0 maxcount/2 maxcount], 2, 'significant');
app.GreenAxes.YLim = [0 maxcount];
app.GreenAxes.YTick = round([0 maxcount/2 maxcount], 2, 'significant');
app.BlueAxes.YLim = [0 maxcount];
app.BlueAxes.YTick = round([0 maxcount/2 maxcount], 2, 'significant');
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, varargin)
% Configure image axes
app.ImageAxes.Visible = 'off';
app.ImageAxes.Colormap = gray(256);
axis(app.ImageAxes, 'image');
end
% Callback function
function DropDownValueChanged(app, event)
% Update the image and histograms
updateimage(app, app.DropDown.Value);
end
% Callback function
function LoadButtonPushed(app, event)
% Display uigetfile dialog
filterspec = {'*.jpg;*.tif;*.png;*.gif','All Image Files'};
[f, p] = uigetfile(filterspec);
% Make sure user didn't cancel uigetfile dialog
if (ischar(p))
fname = [p f];
updateimage(app, fname);
end
end
% Button pushed function: OpenButton
function OpenButtonPushed(app, event)
[filename,filepath] = uigetfile({'*,*';'*.jpg';'*.png';'*.bmp'}, 'Select File to Open');
fullname = [filepath, filename];
ImageFile = imread(fullname);
axes(handles.axes1)
imagesc(ImageFile);
set(handles.axes1,'visible','off') %hide the current axes
set(get(handles.axes1,'children'),'visible','off') %hide the current axes contents
axis off;
end
end
% 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.AutoResizeChildren = 'off';
app.UIFigure.Position = [100 100 1262 767];
app.UIFigure.Name = 'Image Histograms';
app.UIFigure.Resize = 'off';
% Create ImageAxes_2
app.ImageAxes_2 = uiaxes(app.UIFigure);
app.ImageAxes_2.XTick = [];
app.ImageAxes_2.XTickLabel = {'[ ]'};
app.ImageAxes_2.YTick = [];
app.ImageAxes_2.Position = [765 386 429 305];
% Create BrainViewButton
app.BrainViewButton = uibutton(app.UIFigure, 'push');
app.BrainViewButton.Position = [774 707 100 22];
app.BrainViewButton.Text = {'Brain View'; ''};
% Create BloodViewButton
app.BloodViewButton = uibutton(app.UIFigure, 'push');
app.BloodViewButton.Position = [890 707 100 22];
app.BloodViewButton.Text = 'Blood View';
% Create VentriclesViewButton
app.VentriclesViewButton = uibutton(app.UIFigure, 'push');
app.VentriclesViewButton.Position = [1006 707 100 22];
app.VentriclesViewButton.Text = 'Ventricles View';
% Create TissueViewButton
app.TissueViewButton = uibutton(app.UIFigure, 'push');
app.TissueViewButton.Position = [1112 707 100 22];
app.TissueViewButton.Text = 'Tissue View';
% Create InfoPanel
app.InfoPanel = uipanel(app.UIFigure);
app.InfoPanel.AutoResizeChildren = 'off';
app.InfoPanel.Title = 'Info';
app.InfoPanel.Position = [16 707 219 59];
% Create PatientNameLabel_2
app.PatientNameLabel_2 = uilabel(app.InfoPanel);
app.PatientNameLabel_2.HorizontalAlignment = 'right';
app.PatientNameLabel_2.FontWeight = 'bold';
app.PatientNameLabel_2.Position = [15 8 82 22];
app.PatientNameLabel_2.Text = 'Patient Name';
% Create PatientNameEditField
app.PatientNameEditField = uieditfield(app.InfoPanel, 'text');
app.PatientNameEditField.Position = [111 8 100 22];
% Create OptionPanel
app.OptionPanel = uipanel(app.UIFigure);
app.OptionPanel.AutoResizeChildren = 'off';
app.OptionPanel.Title = 'Option Panel';
app.OptionPanel.FontWeight = 'bold';
app.OptionPanel.Position = [13 601 260 98];
% Create OpenButton
app.OpenButton = uibutton(app.OptionPanel, 'push');
app.OpenButton.ButtonPushedFcn = createCallbackFcn(app, @OpenButtonPushed, true);
app.OpenButton.Position = [6 48 100 22];
app.OpenButton.Text = 'Open';
% Create FlipButton
app.FlipButton = uibutton(app.OptionPanel, 'push');
app.FlipButton.Position = [119 48 100 22];
app.FlipButton.Text = 'Flip';
% Create RunButton
app.RunButton = uibutton(app.OptionPanel, 'push');
app.RunButton.Position = [80 7 100 22];
app.RunButton.Text = 'Run';
% Create EditingPanel
app.EditingPanel = uipanel(app.UIFigure);
app.EditingPanel.AutoResizeChildren = 'off';
app.EditingPanel.Title = 'Editing Panel';
app.EditingPanel.FontWeight = 'bold';
app.EditingPanel.Position = [13 289 260 304];
% Create CorrectionButton
app.CorrectionButton = uibutton(app.EditingPanel, 'push');
app.CorrectionButton.Position = [80 250 100 22];
app.CorrectionButton.Text = 'Correction';
% Create CleaningToolForBloodButton
app.CleaningToolForBloodButton = uibutton(app.EditingPanel, 'push');
app.CleaningToolForBloodButton.Position = [58 217 144 22];
app.CleaningToolForBloodButton.Text = 'Cleaning Tool For Blood';
% Create CleaningToolforVentriclesButton
app.CleaningToolforVentriclesButton = uibutton(app.EditingPanel, 'push');
app.CleaningToolforVentriclesButton.Position = [49.5 182 161 22];
app.CleaningToolforVentriclesButton.Text = 'Cleaning Tool for Ventricles';
% Create CleaningToolforCalcificationButton
app.CleaningToolforCalcificationButton = uibutton(app.EditingPanel, 'push');
app.CleaningToolforCalcificationButton.Position = [43 151 174 22];
app.CleaningToolforCalcificationButton.Text = 'Cleaning Tool for Calcification';
% Create MorphologicalOperationsButton
app.MorphologicalOperationsButton = uibutton(app.EditingPanel, 'push');
app.MorphologicalOperationsButton.Position = [54 117 152 22];
app.MorphologicalOperationsButton.Text = 'Morphological Operations';
% Create UndoButton
app.UndoButton = uibutton(app.EditingPanel, 'push');
app.UndoButton.Position = [80 83 100 22];
app.UndoButton.Text = 'Undo';
% Create BloodToolButton
app.BloodToolButton = uibutton(app.EditingPanel, 'push');
app.BloodToolButton.Position = [80 49 100 22];
app.BloodToolButton.Text = 'Blood Tool';
% Create DeleteButton
app.DeleteButton = uibutton(app.EditingPanel, 'push');
app.DeleteButton.Position = [80 16 100 22];
app.DeleteButton.Text = 'Delete';
% Create AnalyzePanel
app.AnalyzePanel = uipanel(app.UIFigure);
app.AnalyzePanel.AutoResizeChildren = 'off';
app.AnalyzePanel.Title = 'Analyze Panel';
app.AnalyzePanel.FontWeight = 'bold';
app.AnalyzePanel.Position = [13 103 260 178];
% Create CreateBoundaryButton
app.CreateBoundaryButton = uibutton(app.AnalyzePanel, 'push');
app.CreateBoundaryButton.Position = [71 133 106 22];
app.CreateBoundaryButton.Text = 'Create Boundary';
% Create SAHButton
app.SAHButton = uibutton(app.AnalyzePanel, 'push');
app.SAHButton.Position = [71 103 100 22];
app.SAHButton.Text = 'SAH';
% Create ICHButton
app.ICHButton = uibutton(app.AnalyzePanel, 'push');
app.ICHButton.Position = [71 72 100 22];
app.ICHButton.Text = 'ICH';
% Create SDHButton
app.SDHButton = uibutton(app.AnalyzePanel, 'push');
app.SDHButton.Position = [71 41 100 22];
app.SDHButton.Text = 'SDH';
% Create IVHButton
app.IVHButton = uibutton(app.AnalyzePanel, 'push');
app.IVHButton.Position = [71 12 100 22];
app.IVHButton.Text = 'IVH';
% Create DataPanel
app.DataPanel = uipanel(app.UIFigure);
app.DataPanel.AutoResizeChildren = 'off';
app.DataPanel.Title = 'Data Panel';
app.DataPanel.FontWeight = 'bold';
app.DataPanel.Position = [14 31 260 65];
% Create AddExplanationButton
app.AddExplanationButton = uibutton(app.DataPanel, 'push');
app.AddExplanationButton.FontSize = 10;
app.AddExplanationButton.Position = [67 21 100 22];
app.AddExplanationButton.Text = 'Add Explanation';
% Create ExportDataButton
app.ExportDataButton = uibutton(app.DataPanel, 'push');
app.ExportDataButton.FontSize = 10;
app.ExportDataButton.Position = [67 0 100 22];
app.ExportDataButton.Text = 'Export Data';
% Create OpenResultsButton
app.OpenResultsButton = uibutton(app.UIFigure, 'push');
app.OpenResultsButton.FontSize = 10;
app.OpenResultsButton.Position = [79 1 100 22];
app.OpenResultsButton.Text = 'Open Results';
% Create StartBrainSliceButton
app.StartBrainSliceButton = uibutton(app.UIFigure, 'push');
app.StartBrainSliceButton.Position = [431 338 100 22];
app.StartBrainSliceButton.Text = 'StartBrainSlice';
% Create EditField
app.EditField = uieditfield(app.UIFigure, 'text');
app.EditField.Position = [547 338 100 22];
% Create FullBrainSliceButton
app.FullBrainSliceButton = uibutton(app.UIFigure, 'push');
app.FullBrainSliceButton.Position = [831 338 100 22];
app.FullBrainSliceButton.Text = 'FullBrainSlice';
% Create EditField_2
app.EditField_2 = uieditfield(app.UIFigure, 'text');
app.EditField_2.Position = [952 338 100 22];
% Create ComputationPanel
app.ComputationPanel = uipanel(app.UIFigure);
app.ComputationPanel.AutoResizeChildren = 'off';
app.ComputationPanel.Title = 'Computation Panel';
app.ComputationPanel.FontWeight = 'bold';
app.ComputationPanel.Position = [303 69 909 221];
% Create AllSlicesPanel
app.AllSlicesPanel = uipanel(app.ComputationPanel);
app.AllSlicesPanel.AutoResizeChildren = 'off';
app.AllSlicesPanel.Title = 'All Slices';
app.AllSlicesPanel.Position = [51 26 421 155];
% Create BrainVolumeEditFieldLabel
app.BrainVolumeEditFieldLabel = uilabel(app.AllSlicesPanel);
app.BrainVolumeEditFieldLabel.HorizontalAlignment = 'right';
app.BrainVolumeEditFieldLabel.FontSize = 10;
app.BrainVolumeEditFieldLabel.Position = [21 101 65 22];
app.BrainVolumeEditFieldLabel.Text = 'Brain Volume';
% Create BrainVolumeEditField
app.BrainVolumeEditField = uieditfield(app.AllSlicesPanel, 'text');
app.BrainVolumeEditField.FontSize = 10;
app.BrainVolumeEditField.Position = [101 101 100 22];
% Create BloodVolumeEditFieldLabel
app.BloodVolumeEditFieldLabel = uilabel(app.AllSlicesPanel);
app.BloodVolumeEditFieldLabel.HorizontalAlignment = 'right';
app.BloodVolumeEditFieldLabel.FontSize = 10;
app.BloodVolumeEditFieldLabel.Position = [19 73 67 22];
app.BloodVolumeEditFieldLabel.Text = 'Blood Volume';
% Create BloodVolumeEditField
app.BloodVolumeEditField = uieditfield(app.AllSlicesPanel, 'text');
app.BloodVolumeEditField.FontSize = 10;
app.BloodVolumeEditField.Position = [101 73 100 22];
% Create VentriclesVolumeEditFieldLabel
app.VentriclesVolumeEditFieldLabel = uilabel(app.AllSlicesPanel);
app.VentriclesVolumeEditFieldLabel.HorizontalAlignment = 'right';
app.VentriclesVolumeEditFieldLabel.FontSize = 10;
app.VentriclesVolumeEditFieldLabel.Position = [15 41 85 22];
app.VentriclesVolumeEditFieldLabel.Text = 'Ventricles Volume';
% Create VentriclesVolumeEditField
app.VentriclesVolumeEditField = uieditfield(app.AllSlicesPanel, 'text');
app.VentriclesVolumeEditField.FontSize = 10;
app.VentriclesVolumeEditField.Position = [108 41 100 22];
% Create TissueVolumeEditFieldLabel
app.TissueVolumeEditFieldLabel = uilabel(app.AllSlicesPanel);
app.TissueVolumeEditFieldLabel.HorizontalAlignment = 'right';
app.TissueVolumeEditFieldLabel.FontSize = 10;
app.TissueVolumeEditFieldLabel.Position = [22 8 71 22];
app.TissueVolumeEditFieldLabel.Text = 'Tissue Volume';
% Create TissueVolumeEditField
app.TissueVolumeEditField = uieditfield(app.AllSlicesPanel, 'text');
app.TissueVolumeEditField.FontSize = 10;
app.TissueVolumeEditField.Position = [101 8 100 22];
% Create BloodStatsPanel
app.BloodStatsPanel = uipanel(app.AllSlicesPanel);
app.BloodStatsPanel.AutoResizeChildren = 'off';
app.BloodStatsPanel.Title = 'Blood Stats';
app.BloodStatsPanel.Position = [216 -12 190 154];
% Create SAHEditFieldLabel
app.SAHEditFieldLabel = uilabel(app.BloodStatsPanel);
app.SAHEditFieldLabel.HorizontalAlignment = 'right';
app.SAHEditFieldLabel.FontSize = 10;
app.SAHEditFieldLabel.Position = [11 106 26 22];
app.SAHEditFieldLabel.Text = 'SAH';
% Create SAHEditField
app.SAHEditField = uieditfield(app.BloodStatsPanel, 'text');
app.SAHEditField.FontSize = 10;
app.SAHEditField.Position = [52 106 100 22];
% Create ICHEditFieldLabel
app.ICHEditFieldLabel = uilabel(app.BloodStatsPanel);
app.ICHEditFieldLabel.HorizontalAlignment = 'right';
app.ICHEditFieldLabel.FontSize = 10;
app.ICHEditFieldLabel.Position = [12 78 25 22];
app.ICHEditFieldLabel.Text = 'ICH';
% Create ICHEditField
app.ICHEditField = uieditfield(app.BloodStatsPanel, 'text');
app.ICHEditField.FontSize = 10;
app.ICHEditField.Position = [52 78 100 22];
% Create SDHEditFieldLabel
app.SDHEditFieldLabel = uilabel(app.BloodStatsPanel);
app.SDHEditFieldLabel.HorizontalAlignment = 'right';
app.SDHEditFieldLabel.FontSize = 10;
app.SDHEditFieldLabel.Position = [10 53 27 22];
app.SDHEditFieldLabel.Text = 'SDH';
% Create SDHEditField
app.SDHEditField = uieditfield(app.BloodStatsPanel, 'text');
app.SDHEditField.FontSize = 10;
app.SDHEditField.Position = [52 53 100 22];
% Create IVHEditFieldLabel
app.IVHEditFieldLabel = uilabel(app.BloodStatsPanel);
app.IVHEditFieldLabel.HorizontalAlignment = 'right';
app.IVHEditFieldLabel.FontSize = 10;
app.IVHEditFieldLabel.Position = [12 20 25 22];
app.IVHEditFieldLabel.Text = 'IVH';
% Create IVHEditField
app.IVHEditField = uieditfield(app.BloodStatsPanel, 'text');
app.IVHEditField.FontSize = 10;
app.IVHEditField.Position = [52 20 100 22];
% Create CurrentSlicePanel
app.CurrentSlicePanel = uipanel(app.ComputationPanel);
app.CurrentSlicePanel.AutoResizeChildren = 'off';
app.CurrentSlicePanel.Title = 'Current Slice';
app.CurrentSlicePanel.Position = [500 4 391 193];
% Create BloodStatsPanel_2
app.BloodStatsPanel_2 = uipanel(app.CurrentSlicePanel);
app.BloodStatsPanel_2.AutoResizeChildren = 'off';
app.BloodStatsPanel_2.Title = 'Blood Stats';
app.BloodStatsPanel_2.Position = [47 22 202 138];
% Create SAHEditField_2Label
app.SAHEditField_2Label = uilabel(app.BloodStatsPanel_2);
app.SAHEditField_2Label.HorizontalAlignment = 'right';
app.SAHEditField_2Label.FontSize = 10;
app.SAHEditField_2Label.Position = [39 88 26 22];
app.SAHEditField_2Label.Text = 'SAH';
% Create SAHEditField_2
app.SAHEditField_2 = uieditfield(app.BloodStatsPanel_2, 'text');
app.SAHEditField_2.FontSize = 10;
app.SAHEditField_2.Position = [80 88 100 22];
% Create ICHEditField_2Label
app.ICHEditField_2Label = uilabel(app.BloodStatsPanel_2);
app.ICHEditField_2Label.HorizontalAlignment = 'right';
app.ICHEditField_2Label.FontSize = 10;
app.ICHEditField_2Label.Position = [40 62 25 22];
app.ICHEditField_2Label.Text = 'ICH';
% Create ICHEditField_2
app.ICHEditField_2 = uieditfield(app.BloodStatsPanel_2, 'text');
app.ICHEditField_2.FontSize = 10;
app.ICHEditField_2.Position = [80 62 100 22];
% Create SDHEditField_2Label
app.SDHEditField_2Label = uilabel(app.BloodStatsPanel_2);
app.SDHEditField_2Label.HorizontalAlignment = 'right';
app.SDHEditField_2Label.FontSize = 10;
app.SDHEditField_2Label.Position = [38 34 27 22];
app.SDHEditField_2Label.Text = 'SDH';
% Create SDHEditField_2
app.SDHEditField_2 = uieditfield(app.BloodStatsPanel_2, 'text');
app.SDHEditField_2.FontSize = 10;
app.SDHEditField_2.Position = [80 34 100 22];
% Create IVHLabel
app.IVHLabel = uilabel(app.BloodStatsPanel_2);
app.IVHLabel.HorizontalAlignment = 'right';
app.IVHLabel.FontSize = 10;
app.IVHLabel.Position = [40 9 25 22];
app.IVHLabel.Text = 'IVH';
% Create IVHEditField_2
app.IVHEditField_2 = uieditfield(app.BloodStatsPanel_2, 'text');
app.IVHEditField_2.FontSize = 10;
app.IVHEditField_2.Position = [80 9 100 22];
% Create EditField_9
app.EditField_9 = uieditfield(app.BloodStatsPanel_2, 'text');
app.EditField_9.Position = [1 37 40 16];
% Create EditField_10
app.EditField_10 = uieditfield(app.BloodStatsPanel_2, 'text');
app.EditField_10.Position = [1 12 40 16];
% Create EditField_11
app.EditField_11 = uieditfield(app.BloodStatsPanel_2, 'text');
app.EditField_11.Position = [1 89 40 16];
% Create EditField_12
app.EditField_12 = uieditfield(app.BloodStatsPanel_2, 'text');
app.EditField_12.Position = [1 65 40 16];
% Create CreateBoundaryStatsPanel
app.CreateBoundaryStatsPanel = uipanel(app.CurrentSlicePanel);
app.CreateBoundaryStatsPanel.AutoResizeChildren = 'off';
app.CreateBoundaryStatsPanel.Title = 'Create Boundary Stats';
app.CreateBoundaryStatsPanel.Position = [248 25 121 133];
% Create EditField_3
app.EditField_3 = uieditfield(app.CreateBoundaryStatsPanel, 'text');
app.EditField_3.Position = [21 88 59 17];
% Create EditField_4
app.EditField_4 = uieditfield(app.CreateBoundaryStatsPanel, 'text');
app.EditField_4.Position = [21 65 59 18];
% Create EditField_5
app.EditField_5 = uieditfield(app.CreateBoundaryStatsPanel, 'text');
app.EditField_5.Position = [21 41 59 20];
% Create EditField_6
app.EditField_6 = uieditfield(app.CreateBoundaryStatsPanel, 'text');
app.EditField_6.Position = [21 17 59 20];
% Create BrainDemoLabel
app.BrainDemoLabel = uilabel(app.UIFigure);
app.BrainDemoLabel.FontSize = 14;
app.BrainDemoLabel.FontWeight = 'bold';
app.BrainDemoLabel.Position = [554 746 84 22];
app.BrainDemoLabel.Text = 'Brain Demo';
% Create ImageAxes_3
app.ImageAxes_3 = uiaxes(app.UIFigure);
app.ImageAxes_3.XTick = [];
app.ImageAxes_3.XTickLabel = {'[ ]'};
app.ImageAxes_3.YTick = [];
app.ImageAxes_3.Position = [303 386 429 305];
% 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 = Patient(varargin)
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
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
Hi Debasish,
Please find my code above. Your suggestions would be very much appreciated. Thank you.
回答(2 个)
Floris
2019-6-11
编辑:Floris
2019-6-11
So based on the code you shared it seems like you have made multiple copies of ImageAxes:
- ImageAxes
- ImageAxes_2
- ImageAxes_3
And in your public properties, just ImageAxes_2 and ImageAxes_3 are initialized. So somehow your original ImageAxes initialization was deleted. So now when your startup function is called it cannot find the ImageAxes property. I believe this happens when you rename a component in the App Designer multiple times, or create it multiple times.
So just add ImageAxes to your properties and you should be good to go!
The code:
classdef Patient < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ImageAxes matlab.ui.control.UIAxes % Renamed this to ImageAxes
% all the other properties ...
end
% All the other functions and properties here ...
end
Warid Islam
2019-6-11
I changed the code and that specific problem seems to be not there any more. However, I am getting a new error.
% Create histograms based on number of color channels
switch size(im,3)
case 1
% Display the grayscale image
imagesc(app.ImageAxes2,im);
% Plot all histograms with the same data for grayscale
histr = histogram(app.RedAxes, im, 'FaceColor',[1 0 0],'EdgeColor', 'none');
histg = histogram(app.GreenAxes, im, 'FaceColor',[0 1 0],'EdgeColor', 'none');
histb = histogram(app.BlueAxes, im, 'FaceColor',[0 0 1],'EdgeColor', 'none');
case 3
% Display the truecolor image
imagesc(app.ImageAxes3,im);
% Plot the histograms
histr = histogram(app.RedAxes, im(:,:,1), 'FaceColor', [1 0 0], 'EdgeColor', 'none');
histg = histogram(app.GreenAxes, im(:,:,2), 'FaceColor', [0 1 0], 'EdgeColor', 'none');
histb = histogram(app.BlueAxes, im(:,:,3), 'FaceColor', [0 0 1], 'EdgeColor', 'none');
otherwise
% Error when image is not grayscale or truecolor
uialert(app.UIFigure, 'Image must be grayscale or truecolor.', 'Image Error');
return;
end
% Get largest bin count
maxr = max(histr.BinCounts);
maxg = max(histg.BinCounts);
maxb = max(histb.BinCounts);
maxcount = max([maxr maxg maxb]);
% Set y axes limits based on largest bin count
app.RedAxes.YLim = [0 maxcount];
app.RedAxes.YTick = round([0 maxcount/2 maxcount], 2, 'significant');
app.GreenAxes.YLim = [0 maxcount];
app.GreenAxes.YTick = round([0 maxcount/2 maxcount], 2, 'significant');
app.BlueAxes.YLim = [0 maxcount];
app.BlueAxes.YTick = round([0 maxcount/2 maxcount], 2, 'significant');
end
end
it says ILLEGAL USE OF RESERVED KEYWORD "SWITCH'.
Thank you.
1 个评论
Rik
2019-6-11
This is not an answer. In future, please also post a link to your question if you choose to re-post something, and also include a link in your new question to the original for context.
And if you have much code (more than about 20 lines), please put it in an attachment to improve the readability of the thread.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
标签
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)