Converting Excel columns to a vector

56 vues (au cours des 30 derniers jours)
Daniel Jednorozec
Daniel Jednorozec le 13 Juil 2012
I am trying to access a specific column from different files and convert them into a matrix to be used later but I am running into problems and I'm not sure what I am doing wrong. Here is the part of my code I am trying to do it in, if anyone can tell me what I'm doing wrong I would greatly appreciate it.
for i = 1:3 % Loop over the files
a = xlsread(dataFiles{i}); % Load the data
c = a(:,3); % takes the third column from the file
hf(:,i) = c*(100^2); % converts the values and makes a matrix
end
Is it that I need to convert the cells to a matrix using cell2mat?
  3 commentaires
Daniel Jednorozec
Daniel Jednorozec le 13 Juil 2012
Sure, sorry about that.
??? Subscripted assignment dimension mismatch.
Error in ==> trajtest at 16
hf(:,i) = c*(100^2);
Nirmal
Nirmal le 13 Juil 2012
it means that the size of hf and size of c are not same. See the size of both hf and c using size() function.

Connectez-vous pour commenter.

Réponse acceptée

Nirmal
Nirmal le 13 Juil 2012
hf=[];
for i = 1:3 % Loop over the files
a = xlsread(dataFiles{i}); % Load the data
c = a(:,3); % takes the third column from the file
hf =[hf c*(100^2)]; % converts the values and makes a matrix
end
This should work for you.
  3 commentaires
Nirmal
Nirmal le 14 Juil 2012
Modifié(e) : Nirmal le 14 Juil 2012
do you know before hand how many rows are there? the error is because you have empty hf. if you dont know then not so elegant way would be to have a loop inside your main loop. Error is saying it needs to know the row size of the matrix.
Daniel Jednorozec
Daniel Jednorozec le 16 Juil 2012
Generally speaking there seems to tend to be 328 rows, but I recently had a file that went for double the time (the rows represent half second data marks), so it can go longer sometimes.

Connectez-vous pour commenter.

Plus de réponses (4)

nanren888
nanren888 le 13 Juil 2012
Are the columns always the same length?
If the dimensions, length of hf(:,i) & c are different you may need to consider
hf(ran,k) = c....
Like Conrad said, can you post the error message?
  1 commentaire
Daniel Jednorozec
Daniel Jednorozec le 13 Juil 2012
Modifié(e) : Daniel Jednorozec le 14 Juil 2012
Columns are always the same length in this case.

Connectez-vous pour commenter.


Daniel Jednorozec
Daniel Jednorozec le 17 Juil 2012
Ok, I figured out the problem. Apparently the first file is being treated as if it is somehow a different length than the other two files, so when I went from file 2 to file 3 it worked perfectly and printed to the excel file exactly as I wanted. So now I just need to see what exactly is different about the first file and I should have what I was looking for. Thank you everyone for your help.

Sidra Khalid
Sidra Khalid le 22 Déc 2018
IMG-20181211-WA0003.jpeg
how i write this program

Sidra Khalid
Sidra Khalid le 22 Déc 2018
IMG-20181211-WA0001.jpgthis is the remaining part..anyone help me please..is convert it from excel to matlab or matlab to exicel?

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by