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 Exchange에서 Oceanography 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