error in loading data from a sheet in .xlsx format
조회 수: 23 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Stephen23
2023년 4월 5일
" I do have the sheet but matlab is still give me error."
No, as the error message correctly states, there is NO sheet in that XLSX named "1". These are the sheetnames:
fnm = 'Mechanical Propulsion System Data.xlsx';
sheetnames(fnm)
If you want to access the first sheet, then specify that as a numeric (just as the documentation shows):
tbl = readtable(fnm,"Sheet",1)
추가 답변 (1개)
Walter Roberson
2023년 4월 5일
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"
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!