Effacer les filtres
Effacer les filtres

Reading several cell (not in range) from a Excel file

3 vues (au cours des 30 derniers jours)
judy abbott
judy abbott le 11 Juil 2016
Commenté : Image Analyst le 11 Juil 2016
Dear all, I'm looking to read a serval cell not in range for example A1, A3 and A50 It work for a cell:
X1 = 1;
Val_X1 = ['A' num2str(X1) ':' 'A' num2str(X1)];
Y1 = xlsread('D:\file_1.xlsx',Val_X1)
Please how i make it work for a vector X1 =[1 3 50] ???
  3 commentaires
judy abbott
judy abbott le 11 Juil 2016
Sorry, i want to say :several, lot, serie or a vector of cell
Image Analyst
Image Analyst le 11 Juil 2016
But what about my Answer below???

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 11 Juil 2016
Asuming you have a recent version of MATLAB, you can do this
Y1(1) = xlsread('D:\file_1.xlsx', 'A1')
Y1(2) = xlsread('D:\file_1.xlsx', 'A3')
Y1(3) = xlsread('D:\file_1.xlsx', 'A50')
If you have a version older than about R2015b, then if you have a lot of these, you should consider ActiveX. But with R2015b and later it shoudl be fast because MATLAB keeps Excel running in the background.
Alternatively, if you have a whole lot of x, then you could do it in a loop:
for k = 1 : length(x)
thisCell = sprintf('A%d', x(k));
Y1(k) = xlsread('D:\file_1.xlsx', thisCell);
end

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by