error in loading data from a sheet in .xlsx format

23 visualizaciones (últimos 30 días)
Othman Alkandri
Othman Alkandri el 5 de Abr. de 2023
Comentada: Othman Alkandri el 5 de Abr. de 2023
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.

Respuesta aceptada

Stephen23
Stephen23 el 5 de Abr. de 2023
" 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)
ans = 6×1 string array
"Ship Specification" "Proppler" "Geerbox" "Egine " "Hotel Load" "Mechanical Propulsion System"
If you want to access the first sheet, then specify that as a numeric (just as the documentation shows):
tbl = readtable(fnm,"Sheet",1)
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
tbl = 18×5 table
parameterSymbol unit Value path description ______________________ ____________ _____ ____ ______________________________________________________________________________________________________________________ {'LBP' } {'m' } 59.4 NaN {'Length between perpendiculars, ship length' } {'Los' } {'m' } 59.4 NaN {'length over surface' } {'Lwl' } {'m' } 59.4 NaN {'the length of a ship or boat at the level where it sits in the water (the waterline)' } {'TF' } {'m' } 2.5 NaN {'draft at forward perpendicular' } {'TA' } {'m' } 0.954 NaN {'draft at aft perpendicular' } {'V_breadth' } {'m' } 12 NaN {'Vessel width' } {'V_Draft' } {'m' } 2.5 NaN {'Vessel draft(draught)' } {'N_thruster' } {'unitless'} 1 NaN {'number of side thrusters' } {'Nrudd' } {'unitless'} 1 NaN {'rudder is part of the steering apparatus of a boat or ship that is fastened outside the hull, usually at the stern'} {'NBoss' } {'unitless'} 1 NaN {'number of bossings' } {'NBrac' } {'unitless'} 1 NaN {'number of brackets' } {'AT' } {'m^2' } 40 NaN {'Transverse area of the ship' } {'CB' } {'unitless'} 0.512 NaN {'block coefficient' } {'mass' } {'ton' } 100 NaN {'ship mass' } {'num people orginal'} {'unitless'} 400 NaN {'number of pepole on the feery at t=0' } {'num car orignal' } {'unitless'} 80 NaN {'number of car on the feery at t=0' }

Más respuestas (1)

Walter Roberson
Walter Roberson el 5 de Abr. de 2023
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"

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by