How can I read a text file and store its data inside a matrix?

조회 수: 6 (최근 30일)
Jacob Lobao
Jacob Lobao 2019년 3월 22일
댓글: Jacob Lobao 2019년 3월 22일
I am trying to import text files, and convert it's data into a matrix. When I import the file, it stores it as a 50x1 cell, how can I convert this to a 50x9 or 50x10 matrix, where I can reference each aspect of the file individually? Screenshot (1).png
fid = fopen ('40_8deg_HL_Both.txt', 'r');
data = textscan(fid, '%s', 'HeaderLines', 9, 'delimiter', '/n');
fclose (fid);
mat = data{:};

채택된 답변

KSSV
KSSV 2019년 3월 22일
clc; clear all ;
fid = fopen ('40_8deg_HL_Both.txt', 'r');
data = textscan(fid, '%s %s %f %f %f %f %f %f %f %s', 'HeaderLines', 9);
fclose (fid);
A = [data{3:9}]
  댓글 수: 1
Jacob Lobao
Jacob Lobao 2019년 3월 22일
Had trouble with the format you specified, but made it work, thanks.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by