error in loading data from a sheet in .xlsx format
显示 更早的评论
I am loading data from sheet one using load button callback as shown below
function ExcelDataLoadButtonPushed(app, event)
%this code taken from the flowwing ref
%https://www.mathworks.com/matlabcentral/answers/1889727-how-to-let-the-user-input-an-excel-file-i-e-csv-file-and-array-in-matlp-app-designer
% knot it's better to have excel files without labe stight data
% the excel file should be in csv
%everytime you need to update you need to clcik on the file
%button
% Have user select Excel file to load
[app.filename, app.folder] = uigetfile('*.xlsx*');
if isequal(app.filename,0)
msgbox('Please input an Excel file')
else
%app.filename = fullfile('Mechanical Propulsion System Data.xlsx');
% Read the Excel data
app.System_data = readtable(fullfile(app.folder,app.filename),"Sheet","1");
%app.System_data = readtable(app.filename,"Sheet","1");
%sotring the data from the master file in the variables
% Ship Specification
app.LBP = app.System_data{1,3};
app.Los = app.System_data{2,3};
app.Lwl = app.System_data{3,3};
app.TF = app.System_data{4,3};
app.TA = app.System_data{5,3};
app.V_breadth= app.System_data{6,3};
app.V_Draft= app.System_data{7,3};
app.N_thruster = app.System_data{8,3};
app.Nrudd = app.System_data{9,3};
app.NBoss = app.System_data{10,3};
app.NBrac = app.System_data{11,3};
app.AT = app.System_data{12,3};
app.CB = app.System_data{13,3};
end
end
the error i have is
Error using readtable
Sheet name '1' does not exist or is not supported. To check if the sheet is supported, specify the sheet by its worksheet index.
Error in Ferry_test_system_main/ExcelDataLoadButtonPushed (line 695)
app.System_data = readtable(fullfile(app.folder,app.filename),"Sheet","1");
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
I attachd the xlsx file. I do have the sheet but matlab is still give me error. could you help me with the error please.
采纳的回答
更多回答(1 个)
Walter Roberson
2023-4-5
0 个投票
you do not have a sheet named "1", you have a sheet named "Mechanical Propulsion System". That sheet is index 1, not named "1". If you want index 1 pass in numeric 1 instead of "1"
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!