コードとエラーメッセージだけでなく、読み込み対象のデータもつけておけば回答を得やすくなるかもしれませんね。
少し頭を使って考えると、簡単に答えにたどり着くことができます。
時間 = csvread (ファイル (n). 名前, 4, 0, [4 0 515 0]);
では正しくデータが読み込めていたが、
時間 = csvread (ファイル (n). 名前, 5, 0, [5 0 2052 0]);
ではエラーとなったわけですから、変更した箇所であるcsvreadの2番目の引数か4番目の引数、もしくは両方に問題があります。
doc csvread
M = csvread(filename, R1, C1, [R1 C1 R2 C2])
で引数を確認すると、変更した箇所はR1“行の開始オフセット”、R2“行の終了オフセット”ということが分かります。
手元で適当なcsvファイルを生成して動作させてみると、R2が実際に格納されている行数よりも多いと同じエラーが発生します。
エラー: dlmread (line 165)
内部サイズの不一致
エラー: csvread (line 50)
m=dlmread(filename, ',', r, c, rng);
エラー: untitled (line 13)
time=csvread(files(n).name, 5, 0, [5 0 2052 0]);
R2とC2を指定するということは、予めデータ数が分かっているはずですから、2052が正しい数値なのかどうかを確認してみてください。
エラーが出た場合は、まずはドキュメンテーションで関数の仕様を確認してみましょう。
(というよりは、引数を変える前にドキュメンテーションを確認しましょう・・・)
エラー再現用csvデータ例
Skip, Skip, Skip, Skip
0,34,23,52
1,52,65,60
エラー再現用コード例
files = dir('*.csv');
[path, name, ext] = fileparts(files.name);
R1 = 1;
R2 = 2;
time=csvread(files.name, R1, 0, [R1 0 R2 0]);
HTH
Best Answer