i am trying to read excel file from D drive under name mirror1 to put values in app.EditData.Value it gives parse error.thanks alot
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
excelfilepath=  'D:\mirror1.xlsx';
data =readtable(excelfilepath);
value=data{1,1};
app.EditField.Value = num2str(value);
end
what is wrong with code
it gives parse erorr
thanks 
6 个评论
  Stephen23
      
      
 2025-7-17
				@m.montaser sabry: to accept an answer please click on the "accept this answer" button. You can only accept one answer.
回答(2 个)
  Fangjun Jiang
      
      
 2025-7-15
        
      移动:Fangjun Jiang
      
      
 2025-7-15
  
      Parse error could mean the error parsing the Excel file. 
Run the first two lines of code in your MATLAB Command window to see if it errors.
excelfilepath=  'D:\mirror1.xlsx';
data =readtable(excelfilepath)
8 个评论
  dpb
      
      
 2025-7-16
				
      编辑:dpb
      
      
 2025-7-16
  
			I simply commented that after you attached error the info Walter had the opportunity to point out where the problem lies...you did not attach the error message in the initial postings so there was no chance until then...
As he notes, you will have to find where the class definitions got messed up and restore them.
Also as he notes, the problem has nothing to do with the code to read the file, the error is telling you something messed up the class definitions structure.
  dpb
      
      
 2025-7-16
				Below is the base code structure from appdesigner of an empty app with only a single button and the stub for a callback from it.
Use this pattern to compare to the sections in your app to find where the structure is broken; the first image has the methods line underlined in red; there's the klew
classdef app1 < matlab.apps.AppBase
  % Properties that correspond to app components
  properties (Access = public)
    UIFigure  matlab.ui.Figure
    Button    matlab.ui.control.Button
  end
  % Callbacks that handle component events
  methods (Access = private)
    % Button pushed function: Button
    function ButtonPushed(app, event)
    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.Position = [100 100 640 480];
      app.UIFigure.Name = 'MATLAB App';
      % Create Button
      app.Button = uibutton(app.UIFigure, 'push');
      app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
      app.Button.Position = [89 344 120 58];
      % 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 = app1
      % 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
  dpb
      
      
 2025-7-16
        
      编辑:dpb
      
      
 2025-7-16
  
      Delete the "end" that you manually entered from the callback function, it's superfluous because app designer builds the function prototype automatically including the function...end lines.  Look at the stub in the sample app I posted earlier.
It seems as though the parser could catch this and be more informative; but when the second "end" was encountered, it closed the class definition too soon and that's where the code parser/analyzer broke.  One might consider submitting an enhancement request that if the user enters an "end" in a stub callback function that would match up with the function of that callback, it be warned; whether that would be feasible or the cure worse than the disease, I don't know, just a thought.
The comment about the dangling "end" statement I made first was/is actually what the problem is; it shouldn't be there.  
What it shows is that one should only add functional code inside the callback functions; App Designer builds the function code.  It also illustrates a problem with MATLAB syntax in that "end" is used to close all structures from classes to functions to if and switch constructs, for loops, and whatever else I've left out.  Consequently, it's not easy to determine what the given "end" relates to; that's why Walter suggested looking at the code indentation tool; it tries to match opening and closing constructs and helps find mismatches.  The editor also will highlight the opening or closing of a construct; if you hover over that "end", you'll see it matches with the function, but then you also have to recognize that the function prototype was already built for you.
3 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




