필터 지우기
필터 지우기

Converting text file to array

조회 수: 229 (최근 30일)
mukesh bisht
mukesh bisht 2021년 3월 27일
댓글: Dyuman Joshi 2023년 10월 20일
Hi.
I want to convert the text file (file attached below) into array of size 4X6. The array should not include the first row (containing characters).
Please help
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 10월 20일
If you have R2019a or later versions, the best approach is to use readmatrix, as Walter has specified.
Otherwise, readtable is the obvious choice.

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

답변 (2개)

Walter Roberson
Walter Roberson 2023년 10월 20일
format long g
arr = readmatrix("WallContacts.txt")
arr = 4×6
1.0e+00 * -0.00275786 0.24992 0.449027 845.871 0 0 -0.00421111 0.455012 0.190379 1260.68 0 0 -0.00385227 0.775165 0.177235 1166.12 0 0 -0.00300194 0.085385 0.172096 905.685 0 0

Ramtej
Ramtej 2023년 10월 20일
Hi mukesh,
I understand that you are trying to import text file data as an array.
In order to achieve this, you can follow below steps:
  • Since, the data in the text file is in a table format. You can import the data as a table using "readtable" function and perform the desired operation on the table itself.
% import the text file as table
tbl = readtable("WallContacts.txt");
  • Once you have imported the data as a table, you can convert it to an array using "table2array" functions as shown below.
% convert it into multidimensional array or matrix
arr = table2array(tbl);
Hope this resolves you query!!

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by