Error between cell and array (matrix)

1 次查看(过去 30 天)
Dear Everyone.
I have my data as attached picture include date, time and price (.txt) with format:
mm/dd/yyyy hh:mm:ss number
04/14/2004 15:00:00 80
04/14/2004 15:30:00 82
04/14/2004 16:00:00 80
......
I tried to run the beginning of my code:
% File contains three columns with date,time and index price respectively
data=Excludeweekendday({'IntervalCLG1996.txt'});
n_uni_t=unique(data(:,[2])); %Unique time stamps
intm=size(n_uni_t);
n=intm(1);
intm=size(data);
n_total_obs=intm(1); %Total number of observations given 5 minutes sampling
i=1;
j=1;
count=0;
while i<=n %Calculate amount of timestamps
for j=1:n_total_obs
if data(j,2)== n_uni_t(i,1)
count=count+1;
end
end
n_uni_t(i,2)=count;
count=0;
i=i+1;
end
end
It did not work with the error:
Undefined operator '==' for input arguments of type 'cell'.
Error in RawRVofnormalandlogreturns (line 23)
if data(j,2)== n_uni_t(i,1)
And
data(i,2)>0.4444 && data(i,2)<0.7431; %Boundaries in matlab format
Norm_data(j,1:3)=data(i,1:3);
When I try to run convert my cell to double with code: b = cellfun(@(x)str2double(x), data); The result of b is totally NaN as picture.
Could you help me find the problem in code and correct it?
I'm really appriciated your help! Picture:

回答(1 个)

Walter Roberson
Walter Roberson 2016-6-18
Try changing
data(j,2)== n_uni_t(i,1)
to
data{j,2} == n_uni_t{i,1}
  3 个评论
Geoff Hayes
Geoff Hayes 2016-6-19
编辑:Geoff Hayes 2016-6-19
Trung - what can you tell us about the dimensions and data type for data and n_uni_t? i.e. what do the following calls return?
size(data)
class(data)
size(n_uni_t)
class(n_uni_t)
Trung Hieu Le
Trung Hieu Le 2016-6-19
Dear Geoff Hayes,
I tried to run the file IntervalCLF1998.txt by code RawRV.... The code is written for array, however, I just have double data. I meet this error:
Attempted to access data(1,2); index out of bounds because size(data)=[70449,1].
Could you help me check in your version which it was run smoothly or not? I used Matlab 2015a.
I'm really appreciate your help.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by