Hello I want to read a .ssv format file in MATLAB and put it in a matrix The file with format .ssv contains 1500 lines and 24 columns Help me please ...For example, this code did not answer. and I dont know what to do
function [training_set, test_set] = read_data(train_path, test_path)
train_file = fopen(train_path);
training_set = cell2mat(textscan(train_file, '%f %f %f %f'));
fclose(train_file);
% open the test data and save to a matrix
test_file = fopen(test_path);
test_set = cell2mat(textscan(test_file, '%f %f %f %f'));
fclose(test_file);

 採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 21 日

1 投票

Change
training_set = cell2mat(textscan(train_file, '%f %f %f %f'));
to
fmt = repmat('%f', 1, 24);
training_set = cell2mat(textscan(train_file, fmt));
and change the test_set from '%f %f %f %f' to refer to fmt as well.

7 件のコメント

f moradi
f moradi 2018 年 6 月 21 日
編集済み: Walter Roberson 2018 年 6 月 21 日
Thank you very much.
You are great.
I wrote this code, but the matrix that create, has only one line and has only two of the numbers in the first line of the .ssv file are written in the matrix. and in the matrix, NaN write for other values.
The values of .ssv file are not numbers and are letters. and has 24 columns , 1500 rows
function [Training, Testing] = read_data(train_path, test_path)
train_file = fopen(train_path);
fmt = repmat('%f', 1, 24);
Training = cell2mat(textscan(train_file, fmt));
fclose(train_file);
test_file = fopen(test_path);
fmt = repmat('%f', 1, 24);
Testing = cell2mat(textscan(train_file, fmt));
fclose(test_file);
end
Walter Roberson
Walter Roberson 2018 年 6 月 21 日
Can you show the first three rows of one of the files?
f moradi
f moradi 2018 年 6 月 21 日
23 0
bdddddddddddddddddddddd
0 f y e t n f c b n t b s s p p p w o p k y d
1 x s w f c f w n u e b s s w w p w o p n v d
f moradi
f moradi 2018 年 6 月 21 日
編集済み: f moradi 2018 年 6 月 21 日
We have to ignore the Three starting lines and we have to put in the matrix, from the Fourth row to the last row of the .ssv file.
f moradi
f moradi 2018 年 6 月 21 日
編集済み: f moradi 2018 年 6 月 21 日
without convert to a matrix, can I use from .ssv file itself? What is the command?
help me please:((
Walter Roberson
Walter Roberson 2018 年 6 月 21 日
I am not at my desk now so I have not looked at the file.
I suggest that you use %s instead of %f and that you add the option 'headerlines', 3
f moradi
f moradi 2018 年 6 月 21 日
ok Thank you

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

その他の回答 (1 件)

f moradi
f moradi 2018 年 6 月 21 日

0 投票

this is my .ssv file.
in the .zip file

カテゴリ

ヘルプ センター および File ExchangeOceanography and Hydrology についてさらに検索

質問済み:

2018 年 6 月 21 日

コメント済み:

2018 年 6 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by