0
我有這種格式的文本文件:如何從文件讀取一行並將其轉換爲數組數組? (八度)
number_of_lines
x1_values y1_values
x2_values y2_values
.
.
.
xn_values yn_values
我掃描NUMBER_OF_LINES後,我怎麼能按行讀其餘線,並將其分成XK,YK分別?
(如果有一行8個值,第4將是X和其他4個爲Y的只有數字。)
我有這種格式的文本文件:如何從文件讀取一行並將其轉換爲數組數組? (八度)
number_of_lines
x1_values y1_values
x2_values y2_values
.
.
.
xn_values yn_values
我掃描NUMBER_OF_LINES後,我怎麼能按行讀其餘線,並將其分成XK,YK分別?
(如果有一行8個值,第4將是X和其他4個爲Y的只有數字。)
我創建了一個文件「yourdata」:
5
10 20
20 30
30 25
40 55
50 60
然後使用例如fscanf或帶標題或fscanf和textscan的textread。
fid = fopen ("yourdata", "r");
lines = fscanf (fid, "%d", 1)
[d] = fscanf (fid, "%f", [lines, 2]);
fclose (fid);
x = d(:, 1)
y = d(:, 2)
給
lines = 5
x =
10
20
20
30
30
y =
25
40
55
50
60
你看的fscanf? – brodoll
在該文件中是否有多於'number_of_lines + 1'的行? –