Negative number using 'csvread' ?

16 ビュー (過去 30 日間)
K T
K T 2015 年 6 月 9 日
コメント済み: K T 2015 年 6 月 9 日
Hi, i'd like to know if there is a chance to read a negative number using 'csvread()' command?
file:
1 -2 10
3 4 -8
Using 'csvread()' I get an array:
1 2 10
3 4 8
Is there any solution? I need to get those negative numbers.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 6 月 9 日
When I use csvread() on a file containing that text, I only get back the first line. But it does have negative values.
When I use dlmread() on the file then everything comes out properly.
Just in case there is something odd about the file you are working with, could you attach a copy of the actual file?
  4 件のコメント
Walter Roberson
Walter Roberson 2015 年 6 月 9 日
fid = fopen('probav2.csv', 'rt');
C = textscan(fid, repmat('%s',1,4*2), 'Delimiter',',');
fclose(fid);
for K = 1 : 4
cols{K} = str2double(strcat(C{K*2-1},{'.'},C{K*2}));
end
now cols{1} will be the first column, cols{2} the second, and so on. If you want them all in one matrix,
Data = horzcat(cols{:});
K T
K T 2015 年 6 月 9 日
It works! Thank you so much.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by