Problem Importing Merged Text From Excel to Matlab

8 visualizaciones (últimos 30 días)
Dima
Dima el 23 de Sept. de 2011
Comentada: Jared Lou el 2 de En. de 2019
Hello!
I wonder if you have experienced such a problem. I am having difficulty importing the text cells in Matlb with the following function:
[Num,Txt,Raw]=xlsread('test.xls');
The text cells are the results of the merging of the various cells that can be like these
D 1 DT D1DT
D 2 DC D2DC
D 3 UT D3UT
D 4 UC D4UC
D 5 DT D5DT
D 6 DC D6DC
the last column is the concatenated result of merging the first three columns....but they are treated as NaN values.....Interesting to note that when I manually types something in excel cell it is treated as text by Matlab...I am not sure why it does not treat merged or concatenated text as the same... I hope this can be overcome somehow..)
I will be happy to hear any opinion!)
Thanks!
D

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 23 de Sept. de 2011
In the Excel sheet, the fourth column contains a formula like "=CONCATENATE(A1,B1,C1)". That must be the reason it was treated as nan by xlsread(). There are ways to deal with it, but that is probably what it is for xlsread(). I didn't research to get to the bottom of it.
I could suggest two solutions.
1. Pre-process the Excel file, you can copy the whole sheet and then paste special, select values.
2. Do the concatenation in MATLAB. If Data is the raw data read in by xlsread, then do this:
Data(:,4)=[Data(:,1),Data(:,2),Data(:,3)];
  5 comentarios
Walter Roberson
Walter Roberson el 24 de Sept. de 2011
I don't have excel to experiment with (and cannot reach my server today anyhow.) I'm wondering whether it would still be treated as NaN if the text "looked like" a number? For example, if you were to =CONCATENATE(B1,B2,B3) then the result should look like 123 -- would that be parsed as a number or as NaN ? Or suppose the result of the concatenation was 'inf' (infinity) -- how would that be interpreted?
I would then try again with numeric formula to see whether the key is that it is a formula, or the key is that it is text, or the key is that it is text that is not interpretable as a number.
Fangjun Jiang
Fangjun Jiang el 24 de Sept. de 2011
Maybe it's even related to MATLAB version, MS Office Version and OS version. I just tried on R2007b, Office 2003 and Windows XP.
>> [Num,Txt,Raw]=xlsread('test.xls')
Num =
1 2 3 6
Txt =
'A' 'B' 'C' 'ABC'
Raw =
'A' 'B' 'C' 'ABC'
[1] [2] [3] [ 6]
In the Excel file, D1=CONCATENATE(B1,B2,B3) D2=SUM(A2:C2).
It looks like xlsread() reads the value.

Iniciar sesión para comentar.


Dima
Dima el 23 de En. de 2012
I am still having problem IMPORTING THE CONCATENATED text...I wonder if anyone has encountered such a problem before? thanks!
  1 comentario
Jared Lou
Jared Lou el 2 de En. de 2019
I'm having a similar problem. I found another thread where someone resorted to readtable. It sounds like some suspect it's related to a specific combo of matlab version, excel version & OS?

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by