How to import and read Excel input into an executable

3 vues (au cours des 30 derniers jours)
deep
deep le 17 Déc 2018
Commenté : deep le 1 Fév 2019
Hello everyone
I need help with reading an excel file as an input into my code which i plan to convert to an executable.
I have to read the data from the excel in such a way that the data from the row 1 and column 1 is assigned to a particular variable in the code, there are 88 such variables. I must access the excel interactively from a file location , then read it and assign the value to these variables.
Can anyone help me with the same, i have limited knowledge in matlab and any lead is Highly appreciated.
Thank you
  2 commentaires
Bob Thompson
Bob Thompson le 17 Déc 2018
What kind of flexibility do you have on how you access your data? Is this some kind of homework problem that you have to do exactly what they ask?
deep
deep le 18 Déc 2018
I have complete flexibility on accesing the data. No restriction.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 17 Déc 2018
readtable will read an excel file and directly transform each column into variables of a table.
I would not recommend having over 80 different variables in any function/script. It would be a complete maintenance nightmare and a clear indication that the design has not been thought out properly. A table would be a lot easier to manipulate.
  6 commentaires
Guillaume
Guillaume le 19 Déc 2018
Could you please elaborate on your first point, that will help me in improving my code.
I think it would be better if you showed an example of your code, then we can see if there's a better way of doing it.
deep
deep le 21 Déc 2018
Sure,
I have attached the file for your perusal.

Connectez-vous pour commenter.

Plus de réponses (1)

Luna
Luna le 17 Déc 2018
Hi,
You can try below to get all excel data.
[fName,pName] = uigetfile({'*.xlsx';'*.xls'},'Please Select an excel file'); % ask you to put excel file and gets file and path names
[num,txt,raw] = xlsread(fullfile(pName,fName)); % reads the excel and gets the numeric as double array, text as cell array and raw data as cell array
var1 = raw{1,1};
var2 = raw{1,2}; % etc...
% OR if all your data is numeric
var1 = num(1,1);
var2 = num(1,2); % etc ...
% you can also use for loops
OR you can also use Activex but it is a bit complicated see link below:
  4 commentaires
deep
deep le 31 Jan 2019
Thank you
deep
deep le 1 Fév 2019
I have observed that Xlswrite works,
Could you please tell me the reason for recommending ActiveX?
Thank you

Connectez-vous pour commenter.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by