Why doesn't csvread read properly?

Hello,
I'm using csvread() to read my stored data from oscilloscope. Original file is 5000 rows long, but when I read .csv file it only reads to half of the file and every second value is 0. In the end vector is still 5000 row long but it's only half of the original. Why it does that and should I rather use textscan()?

3 件のコメント

Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日
>> M = csvread('U_I_MS.csv');
>> size(M)
ans =
5001 3
>> M(1:5,:)
ans =
0.00000 0.00000 0.00000
0.00000 6.00313 60.00390
0.00048 55.20310 20.50390
0.00096 65.60310 29.00390
0.00144 25.60310 2.50391
Two questions:
  1. What version of MATLAB are you using?
  2. Why does the CSV file have semicolons at the end of each line?
Niko
Niko 2017 年 7 月 20 日
I'm using Matlab R2015a. Where do you see semicolons at the and of each line?
Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日
@Niko: a CSV file is a text file, so I opened it using Notepad++. How do you look at a text file?

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

 採用された回答

Jan
Jan 2017 年 7 月 20 日

0 投票

I cannot imagine why your CSVREAD does not work. Perhaps you are reading the wrong file? The 2 semicolons at the end of the line are not nice, but the import should work inspite of this. Nevertheless, it is easy to import the file manually:
fid = fopen(FileName, 'r');
if fid == -1, error('Cannoten read file: %s', FileName); end
fgetl(fid); % Skip first line
Data = fscanf(fid, '%g, %g, %g ;;', [3, inf]).';
fclose(fid);

その他の回答 (1 件)

Kaelasha Tyler
Kaelasha Tyler 2018 年 3 月 17 日

0 投票

I have had exactly the same problem as Niko. While it is possible to manually import the file as Jan says, it would be nice to know why the csvread command is not working as it should, and what to do about it. Any further suggestions, much appreciated.

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

質問済み:

2017 年 7 月 20 日

回答済み:

2018 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by