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

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Jun. 2018

1 Stimme

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 Kommentare

f moradi
f moradi am 21 Jun. 2018
Bearbeitet: Walter Roberson am 21 Jun. 2018
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 am 21 Jun. 2018
Can you show the first three rows of one of the files?
f moradi
f moradi am 21 Jun. 2018
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 am 21 Jun. 2018
Bearbeitet: f moradi am 21 Jun. 2018
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 am 21 Jun. 2018
Bearbeitet: f moradi am 21 Jun. 2018
without convert to a matrix, can I use from .ssv file itself? What is the command?
help me please:((
Walter Roberson
Walter Roberson am 21 Jun. 2018
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 am 21 Jun. 2018
ok Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

f moradi
f moradi am 21 Jun. 2018

0 Stimmen

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