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 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 3 de Feb. de 2023
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')

Más respuestas (1)

Walter Roberson
Walter Roberson el 3 de Feb. de 2023
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()

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by