How do you ask the user to load a path from the .xlsx file, then store it in variables with some concerns when reading the .xlsx file using app designer?

조회 수: 2 (최근 30일)
Hello, guys
I am working on loading the excel file into my app designer. The user should be able to load .xlsx and edit the elements in the excel sheet. The data types in the .xlsx are numbers or paths to another .xlsx file. For the paths in the code, I want to bring the data in .xlsx and store it in variables "time, speed."
I have some concerns when loading the .xlsx
1- The empty cell on the 4th column (Constant noncostant parameters) appears as NaN instead of just keeping it blank. how can i make them blanl cells instead if NaN
2- I have Eidit Field (Text) for the user to put his (new speed profile) excel path. Once the path is sotred, it will show up in the excel sheet. Then in the code, I want to store the variables "time, speed."
Could you please help me with my issues?

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 3일
There are a few points to consider here. Using readmatrix(), readtable(), readcell() and writetable(), e.g.:
A1 = readmatrix("final_speed_profile.csv");
A1 = array2table(A1);
A1 = renamevars(A1, {'A11', 'A12'}, {'time', 'speed'});
% Writes the loaded/imported data to anothe MS Excel file with headers:
% [time speed]
writetable(A1, 'Data.xlsx')
% Reading data from MS Excel: 'Mechanical Propulsion System Data.xlsx using
% readtable()
A2 =readtable('Mechanical Propulsion System Data.xlsx')
% Reading data from MS Excel: 'Mechanical Propulsion System Data.xlsx using
% readcell()
A3 =readcell('Mechanical Propulsion System Data.xlsx')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 2월 3일
I opened in the file in Excel. In the first sheet in the file, "AC No ESS", there are only 5 columns, and readtable() finds them all.
readtable() is detecting that the first two lines are headers and that the third line is something that could be interpreted as column names.
Probably the easiest way to force it to read the first two lines as well would be to use detectImportOptions() on the file, and change the HeaderLine range to empty, and change the data lines range to start at row 1. When you do this, it is possible that it will not be able to read the variable names, so you might have to set the variable names as part of the import options.
readtable() is detecting column 4 as being numeric. numeric columns cannot be blank. If you must have blank entries at those places, then you have two possibilities:
  1. use the import options and setvartype() of column 4 to be text so that everything is read in as pure text (and you will need to manually convert the numbers to numeric if you need them as numeric); Or
  2. use readcell() instead of readtable() . This would also solve the issues with the header lines.
The detection as being numeric is also why paths in column 4 would be converted to NaN.
Perhaps you should switch to readcell()

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by