The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Read from file into matrix
Replies: 1   Last Post: May 5, 2013 4:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 6,677
Registered: 2/7/05
Re: Read from file into matrix
Posted: May 5, 2013 4:54 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 5/5/2013 3:17 AM, Gabriel wrote:
> I have a file with entries like
> 0, "150 145 2 55 13 54 ..."
> There are 2304 numbers in quotes. And I have more than 22 000 of such entries.
> So I need to read them from file one by one.
> How can I do this?

You can try using textscan, using '%d%s' format.

One you read the 2 fields, you can then break the second
field (the string) into its parts using something like
strread(). Like this

s='150 145 2 55 13 54'
c=strread(s,'%s','delimiter',' ')


once you have the parts broken, you can now
easily convert them to numbers, say using

cell2mat(cellfun(@str2num,c, 'UniformOutput',false))

ans =


So, you have everything you need to build your matrix
from what is in the file.


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.