Azzera filtri
Azzera filtri

Error between cell and array (matrix)

1 visualizzazione (ultimi 30 giorni)
Trung Hieu Le
Trung Hieu Le il 18 Giu 2016
Modificato: Geoff Hayes il 19 Giu 2016
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:

Risposte (1)

Walter Roberson
Walter Roberson il 18 Giu 2016
Try changing
data(j,2)== n_uni_t(i,1)
to
data{j,2} == n_uni_t{i,1}
  3 Commenti
Geoff Hayes
Geoff Hayes il 19 Giu 2016
Modificato: Geoff Hayes il 19 Giu 2016
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 il 19 Giu 2016
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.

Accedi per commentare.

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by