tech_enthusiast
tech_enthusiast

Reputation: 693

Read text file in matlab

I am trying to read a text file in matlab. I have done this, but I don't know how to store this value in an array.

My text file contains data like this:

01 ff 02 ff 02 ff 02 ff 03 ff 02 ff

file = fopen(fpath,'r');
allData = textscan(file, '%s', 'delimiter','\n');
for i = 1:491003
    newData = allData{1,1}{i};
end

I want to store each row in separate array, something like this:

a[0] = '01 ff 02 ff' a[1] = '02 ff 02 ff'

Once I have such arrays, I want to access each value of this arrays, something like this:

a[0][0] = 01, a[0][1] = ff, a[0][2] = 02.. a[1][0] = 02, a[1][1] = ff, a[1][2] = 02..

I am new to MATLAB and couldn't find much help myself. Plz help.

Upvotes: 0

Views: 250

Answers (2)

tech_enthusiast
tech_enthusiast

Reputation: 693

Ok, I finally got my answer. I used "Import Data" facility which is available in Matlab 2013. It really helps you to get your data in the way you want.

Cheers.

Upvotes: 0

prgao
prgao

Reputation: 1787

allData = textscan(file, '%s %s %s %s');

allData will be a cell array

Upvotes: 1

Related Questions