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);

 采纳的回答

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 个评论

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
Can you show the first three rows of one of the files?
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:((
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
ok Thank you

请先登录,再进行评论。

更多回答(1 个)

f moradi
f moradi 2018-6-21

0 个投票

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

Community Treasure Hunt

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

Start Hunting!

Translated by