필터 지우기
필터 지우기

Error between cell and array (matrix)

조회 수: 1 (최근 30일)
Trung Hieu Le
Trung Hieu Le 2016년 6월 18일
편집: Geoff Hayes 2016년 6월 19일
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