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

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 Comments

You forgot to attach the actual error message, so we don't know what was complained of...but, the code snippet posted is incomplete with a superfluous "end" statement; the beginning "if" or whatever is to match isn't shown.
The error will be somewhere else in a malformed statement--perhaps a missing closing parenthesis or bracket and this is where the parser finally broke...

I am not using if where . Also statement methods has red line beneath it i am using button pushed to start. so no if is used.thanks

If you have another opinion with same target please write code to solve it I will be thankful.

We can't see your terminal from here, so all we know is what you post -- and that code does have an unmatched "end" in it.
Again, unless you copy and attach the complete text of all red error messages in the context of the code, there's nothing more anybody here can say; we can't see the rest of the code where the problem must be, and as noted, the actual error is undoubtedly somewhere prior to where the code parser actually failed.
@m.montaser sabry: to accept an answer please click on the "accept this answer" button. You can only accept one answer.

Sign in to comment.

Answers (2)

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 Comments

It works and bring stored data under var1 and var2 So what are problem in my code using app designer. Waiting your advise Thank a lot

I attached image to code to show you message which I received
Thank you again
The error has nothing to do with reading the table and so on. The error has to do with the methods clause.
I speculate that you may have accidentally removed an end statement, so the methods (access = private) clause is nested inside the previous methods clause
Try using the editor "Smart Indent" feature. That is in the editor toolstrip in the Refactor section, and the icon looks sort of like a > character . I am not sure about Windows, but I think the corresponding key sequence is control-I
Ah! As we knew, the atual error is far removed from the posted code and where the parser broke...but there's no way could have had any idea what the problem might be without at least a hint of what the reported error was. And, as surmised, the unbalanced end undoubtedly does have something to do with it...

Thank you for you comment but I sent 3 photos showing errors ,i wrote code as you see if you have another way to write new code to have the same target i thank you.

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.
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

Sign in to comment.

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.

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Asked:

on 15 Jul 2025

Commented:

on 17 Jul 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!