I used [Num,Txt,Raw]=xlsread to import a vector that only contains zeros and ones. The problem is that "Num" do not get a single value. The numbers gets read as text and Txt gets all the values. Anyone that have an idea how to fix this? I have used the same technique on same type of vectors before but just this one is not so nice to me.

5 commentaires

Andrei Bobrov
Andrei Bobrov le 18 Mar 2016
Modifié(e) : Andrei Bobrov le 18 Mar 2016
Please give example your xlsx file with small part of your data
Alexander Magnusson
Alexander Magnusson le 18 Mar 2016
Modifié(e) : Walter Roberson le 18 Mar 2016
[1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0]
Walter Roberson
Walter Roberson le 18 Mar 2016
If that is your csv file, then the "[" and "]" would signal that the column is text rather than numeric.
Alexander Magnusson
Alexander Magnusson le 18 Mar 2016
Its just a sample of my vector. I added the [] when printing it here. The column in excel is just excisting of zeros and ones. Even if it was text in the column, Num of [Num,Txt,Raw] should still take all the numbers of the vector and Txt the rest. I have done this correct in other vectors containing different numbers and it works all fine, but just this vector gets read as text because some strange reason.
Walter Roberson
Walter Roberson le 21 Mar 2016
Could you attach a copy of it for testing ?

Connectez-vous pour commenter.

Réponses (2)

somayyah jurair
somayyah jurair le 18 Mar 2016
Modifié(e) : somayyah jurair le 18 Mar 2016

0 votes

If your xls file only contain numeric values then use: num=xlsread(filename) while if it has both numeric as well as string data use [num,text]=xlsread(filename,sheet). You can later assign variables to your imported data using a=num(:,1) b= text(:,1) depending upon the column number of your imported data

3 commentaires

Alexander Magnusson
Alexander Magnusson le 18 Mar 2016
That doesnt work. I usually import the data that way but in this case I only got num=[].
somayyah jurair
somayyah jurair le 18 Mar 2016
In that case check cell format in xls file it may be text that is why MATLAB is importing it as text
Alexander Magnusson
Alexander Magnusson le 21 Mar 2016
I have done that too and it have the same format as the other vectors that work to import to matlab. The text is formated as general and I have tried to change it to number as well but it is still the same problem that is happening.

Connectez-vous pour commenter.

Ahmet Aloglu
Ahmet Aloglu le 5 Déc 2017

0 votes

Somehow I have encountered this same problem. I had used exact same code for my previous runs, and they worked smoothly. Today, this problem occurred to my excel data. I found out that somehow xlsread reads the numbers as text, and store them into a cell array. So I just used
x1 = str2double (x)% x is the cell array that stored numbers as text.
to convert my cell array to double so now I have the extracted numbers from excel files. Just wanted to share this as a way to overcome this problem, unless there would be a better way to solve it.

1 commentaire

Walter Roberson
Walter Roberson le 5 Déc 2017
Would it be possible to attach a sample file for testing?
Also, are you using MS Windows with Excel (Office) installed?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by