Extract data using textscan

조회 수: 1 (최근 30일)
Sana Ejaz
Sana Ejaz 2019년 3월 8일
댓글: Sana Ejaz 2019년 3월 8일
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);

채택된 답변

KSSV
KSSV 2019년 3월 8일
Read about csvread, readtable and xlsread.
[num,txt,raw] = xlsread('CRSP test.csv') ;
  댓글 수: 3
Stephen23
Stephen23 2019년 3월 8일
"I need to use textscan.Thats the only way I have to do it."
Then why did you accept this answer?
Accepting an answer tells everyone that your question has been resolved.
Sana Ejaz
Sana Ejaz 2019년 3월 8일
Oh, I am new to this forum I didn't know that.
I appologise for that.My question haven't been resolved.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by