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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Jun. de 2018

1 voto

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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (1)

f moradi
f moradi el 21 de Jun. de 2018

0 votos

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

Categorías

Más información sobre Oceanography and Hydrology en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Jun. de 2018

Comentada:

el 21 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by