필터 지우기
필터 지우기

How to convert data from txt file to Matlab Arrays

조회 수: 1 (최근 30일)
Shahab Khan
Shahab Khan 2020년 11월 5일
댓글: Walter Roberson 2020년 11월 5일
I have a txt file having some data. I have attached it to this question.
Below is first line from txt file.
16:14:45.077,X,21.4,700,0.0,45,-500,50,555,-38
Each data set is separated by comma. I want to convert them to matlab arrays.
As a result I should get 10 arrays.
for example:
a = 16:14:45.077
b = X
d = 21.4
e = 700
f = 0.0
g = 45
h = -500
i = 50
j = 555
k = -38
I have tried few methods but nothing works properly.
Can anyone please guide me how to do?
Regards

답변 (1개)

Victor Alves
Victor Alves 2020년 11월 5일
편집: Victor Alves 2020년 11월 5일
try this code:
data = dlmread('filename.txt');
save('filename.mat', 'data');
  댓글 수: 3
Victor Alves
Victor Alves 2020년 11월 5일
maybe
then, simply, try:
data = readtable('filename.txt')
it should work with the X
Walter Roberson
Walter Roberson 2020년 11월 5일
t = readtable('filename.txt', 'readvariablenames',false);
a = t{:,1};
b = t{:,2};
c = t{:,3};
d = t{:,4};
e = t{:,5};
f = t{:,6};
g = t{:,7};
h = t{:,8};
i = t{:,9};
j = t{:,10};
... but generally speaking it would typically be easier to
t = readtable('filename.txt', 'readvariablenames',false);
t.Properties.Variablenames = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
and then refer to t.a instead of a, t.f instead of f and so on.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by