How to solve Dataset loading problem?

I am trying to load a dataset about daily living activities on matlab.The content of the txt file contains the following information
2011-11-28 02:27:59 2011-11-28 10:18:11 Sleeping
2011-11-28 10:21:24 2011-11-28 10:23:36 Toileting
2011-11-28 10:25:44 2011-11-28 10:33:00 Showering
2011-11-28 10:34:23 2011-11-28 10:43:00 Breakfast
2011-11-28 10:49:48 2011-11-28 10:51:13 Grooming
2011-11-28 10:51:41 2011-11-28 13:05:07 Spare_Time/TV
2011-11-28 13:06:04 2011-11-28 13:06:31 Toileting
2011-11-28 13:09:31 2011-11-28 13:29:09 Leaving
2011-11-28 13:38:40 2011-11-28 14:21:40 Spare_Time/TV
2011-11-28 14:22:38 2011-11-28 14:27:07 Toileting
2011-11-28 14:27:11 2011-11-28 15:04:00 Lunch
2011-11-28 15:04:59 2011-11-28 15:06:29 Grooming
2011-11-28 15:07:01 2011-11-28 20:20:00 Spare_Time/TV
2011-11-28 20:20:55 2011-11-28 20:20:59 Snack
2011-11-28 20:21:15 2011-11-29 02:06:00 Spare_Time/TV
2011-11-29 02:16:00 2011-11-29 11:31:00 Sleeping
2011-11-29 11:31:55 2011-11-29 11:36:55 Toileting
2011-11-29 11:37:38 2011-11-29 11:48:54 Grooming
2011-11-29 11:49:57 2011-11-29 11:51:13 Showering
2011-11-29 12:08:28 2011-11-29 12:18:00 Breakfast
2011-11-29 12:19:01 2011-11-29 12:22:00 Grooming
2011-11-29 12:22:38 2011-11-29 12:24:59 Spare_Time/TV
2011-11-29 13:25:29 2011-11-29 13:25:32 Snack
2011-11-29 13:25:38 2011-11-29 15:12:26 Spare_Time/TV
2011-11-29 15:13:28 2011-11-29 15:13:57 Toileting
2011-11-29 15:14:33 2011-11-29 15:45:54 Lunch
I want to read the txt file with the "textscan" method, but my code is not working. I get this error message whenever i try to compile the script.
"Conversion to double from cell is not possible.
Error in Untitled (line 10)
x(i,pat)=(Data(i,pat));"
This is my code
fh=fopen('OrdonezA_ADLs.txt');
Data=textscan(fh, '%s,datenum(%s),%s,datenum(%s),%s');
fclose(fh);
n=length(Data);
P=length(Data{1});
x=zeros(n,P);
for pat=1:P
for i=1:n
x(i,pat)=(Data(i,pat));
end
end

 Respuesta aceptada

Star Strider
Star Strider el 29 de Mayo de 2017
Try this:
Data=textscan(fh, '%s%s%s%s%s');
You may need other name-value pair arguments such as 'Delimiter', 'MultipleDelimsAsOne', CollectOutput, and others.
Also, it is best to use the size function here:
n=size(Data,1);

2 comentarios

kpl
kpl el 29 de Mayo de 2017
Thank you very much!It worked fine!
Star Strider
Star Strider el 29 de Mayo de 2017
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

kpl
el 29 de Mayo de 2017

Editada:

el 29 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by