Extract data using textscan
2 次查看(过去 30 天)
显示 更早的评论
Hi,
So I am using textscan for reading and storing specific columns of my raw data and below is the code I am using for it.I am trying to store data from
'new' which is a cell array to 'datasample' that is an array. when I run the code , datasample just have got first column from new and
values of first column has been copied to all other columns too.I have got 4 columns in data sample and all 4 have got values of first column of new.
Somehow 2 ,3 and 4th column of new is not there in data sample.I need all 4 columns of new into datasample.I have attached my data here.
clear
clc
nolines = 0;
fid= fopen('CRSP test.csv');
tline = fgetl(fid);
while ischar(fgetl(fid))
nolines = nolines+1;
end
fclose(fid);
fid = fopen('CRSP test.csv');
tline1 = fgetl(fid);
datasample=zeros(nolines,4);
alldata=cell(10,1);
k=1;
for i = 1:nolines
tline = fgetl(fid);
new = textscan(tline,['%f %s %*s %*s %*f %*s %f',...
repmat('%*f',[1,6]),'%f','%*[^/n]'],'delimiter',',');
datasample(i,:)= new{1,:}; %data in new is not transfering properly to datasample
if (i>1)
if (datasample(i)~=datasample(i-1))
alldata{k,1}=datasample(datasample== datasample(i-1,1));
k=k+1;
end
end
end
fclose(fid);
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!