importdata() function stopped working in Matlab r2020b

3 visualizaciones (últimos 30 días)
Sofia Blanter
Sofia Blanter el 19 de Oct. de 2020
Comentada: Sofia Blanter el 24 de Nov. de 2020
Hallo everyone,
I have a script that uses the importdata() function on a .txt file with a 15 columns. If I run the script under r2019b or r2017b it works fine, if I run exactly the same script with r2020b it doesn't find anything in the file except for the headers. It's the same matlab script file and the same readout .txt file.
In 2019/2017 it would look like:
>>fil = 'C:/Location of file/file.txt'
>> M=importdata(fil)
M =
struct with fields:
data: [125×14 double]
textdata: {126×15 cell}
In 2020b it would look like:
>>fil = 'C:/Location of file/file.txt'
>> M=importdata(fil)
M =
struct with fields:
data: 0
textdata: {1×15 cell}
This has been tested both through script and by just using the above snippet in terminal.
Would anyone have an idea what is going on?
Thanks in advance
UPDATE: Apparantly the issue is somehow related to the hexadecimals. One of the columns is full of hexadecimals, which in Matlab r2020 are read out differently than in r2019. If I use readtable() function in 2020, it will read them, but as "uint 32" format, which could be converted back to the original hexadecimal by the dec2hex function. In 2019 version and below the same column is read in as an array of strings.
But that still does not explain why impordata() was able to read them before but is completely unable to read the full file (only one column is hexadecimals, if I remove it, it reads the file fine) in the 2020 version.
  3 comentarios
Ajay Neeli
Ajay Neeli el 24 de Nov. de 2020
I tried to reproduce this error at my end. I tried to import a text file which has a column of hexadecimals. I tried to import in R2020a, R2018b, R2019b versions. All of them produce the same results. This error might be more than just importdata() function.
Here is the text file I have used for import -
myfile01.txt:
Day1 Day2 Day3 Day4 Day5 Day6 Day7
95.01 76.21 61.54 40.57 5.79 20.28 A
23.11 45.65 79.19 93.55 35.29 19.87 A
60.68 1.85 92.18 91.69 81.32 60.38 A
48.60 82.14 73.82 41.03 0.99 27.22 A
89.13 44.47 17.63 89.36 13.89 19.88 A
The commands I have used for
A = importdata('myfile01.txt',' ',1)
R2020a, R2019b, R2018b produce same output.
A =
struct with fields:
data: [5×7 double]
textdata: {'Day1' 'Day2' 'Day3' 'Day4' 'Day5' 'Day6' 'Day7'}
colheaders: {'Day1' 'Day2' 'Day3' 'Day4' 'Day5' 'Day6' 'Day7'}
Sofia Blanter
Sofia Blanter el 24 de Nov. de 2020
Dear Ajay,
Thank you for your answer.
After having so much trouble with importdata(), we've been using the readtable() function and trying to adjust the matlab script so that it first checks for version, then acts accordingly, by either converting (for r2019b) or not converting (r2020b) the read-out hexadecimals to "uint 32 format":
cd path/to/needed/folder
filename = 'file.txt'
T = readtable(filename);
UID = T.UID;
if strcmp(VersMatlab,'2020b') || strcmp(VersMatlab,'2020a')
UID_converted = UID;
else
for i=1:length(UID)
UID_converted(i) = str2num(UID{i});
end
end
With UID being the column containing hexadecimals. As it turns out, depending on the file format (I believe, I'm not sure), in the r2020b version either this column is read as a string cell aray, or as uint 32 array. If I'm correct, .csv or .txt would read it as "uint 32", and the .xlsx would read it as strings. But I haven't properly tested it.
In any case, our UID column would look something like this:
UID
0x2b387e39
0x2b387f2d
0x2b38801f
As you can see, those look different than the ones in your example. Could that be the reason you're having trouble reproducing the bug?
Thanks in advance

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by