How I can read data from excel according to the name of the header?

6 vues (au cours des 30 derniers jours)
Ivan Enrique Zuñiga
Ivan Enrique Zuñiga le 27 Juil 2012
How I can read data from excel according to the name of the header?
I want to store the data of the column as a vector with the same name in the header.
I use the xlsread() function but I want to know how extract a column vector searching the name of the header.
thank you very much.
  2 commentaires
Image Analyst
Image Analyst le 28 Juil 2012
Where does the header come from? Does it also reside in the workbook, or did it come from your MATLAB program? What are the different ways you want to read data according to what the header is? Like if the header = 'header #1' you want to read it one way, but it the header = 'header #2' you want to read it some other way. It looks like you want to look at the header and then extract different columns depending on what the header looks like. But there is not enough information for us to say anything more, other than you might look at string functions like strfind() and strcmpi().
Where do you want to store the "data of the column"? In a MATLAB variable, or someplace in the workbook?
Ivan Enrique Zuñiga
Ivan Enrique Zuñiga le 28 Juil 2012
I know the name of the header in an Excel workbook, the header can be repositioned in other Excel books. I want bring the column vector to workspace matlab, data of vector are the same underneath the header in excel.

Connectez-vous pour commenter.

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 28 Juil 2012
Modifié(e) : Azzi Abdelmalek le 28 Juil 2012
[v,T,vT]=xlsread('book1.xlsx') % book1.xlsx your file
n=size(v,2); % n: number of column of your matrix
for k=1:n
eval(strcat(T{k},'=v(:,k)'));
end
  2 commentaires
Masoud Ghanbari
Masoud Ghanbari le 21 Juin 2013
Hi
Then How Should we Load book1.xlsx to matlab ???
Azzi Abdelmalek
Azzi Abdelmalek le 21 Juin 2013
[v,T,vT]=xlsread('book1.xlsx')

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 28 Juil 2012
Why can't you just use strfind() or strcmpi() on each cell returned from xlsread() until you find the column you're looking for?

Community Treasure Hunt

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

Start Hunting!

Translated by