필터 지우기
필터 지우기

TEXTSCAN - .csv - mutliple columns to a vector/double/matrix

조회 수: 1 (최근 30일)
Jon Ericson
Jon Ericson 2012년 5월 5일
--
data.csv
t1 1 5 [4 5 8] [3 4 5]
--
How can I use textscan to import the [4 5 8] and the [3 4 5] so that they are converted to 1x3 doubles? As though it were entered at the prompt as:
a = [4 5 8]
fid = fopen('data.csv')
data = textscan(fid,...
'%s %f %f [%f %*f %f] [%f %*f %f]')
Note that I'm trying to skip the middle values (5 and 4) using the *.
Doesn't seem to work! I've tried a number of variations on this and I always get weird results.

답변 (1개)

Oleg Komarov
Oleg Komarov 2012년 5월 5일
I don't get strange results but expected behaviour of textscan.
cell2mat(data(:,2:end))
or when importing:
data = textscan(fid, '%s%f%f[%f%*f%f][%f%*f%f]','CollectOutput',1);
data = data{2};

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by