Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
URGENT: Read text file and save matrices

Subject: URGENT: Read text file and save matrices

From: Diego Zegarra

Date: 13 Oct, 2008 22:30:20

Message: 1 of 8

Hey guys I want to be able to read a bunch of files with the following type of structure but they all have different data dimensions.

3
10

81 79 85
97 91 75
60 98 79
56 74 74
64 86 90
59 98 74
53 56 50
90 76 68
53 57 60
73 72 62

69 74 75 62 76 55 67 55 78 96
69 79 69 97 53 59 72 76 54 56
89 78 91 72 59 52 92 96 95 95
74 98 99 68 55 69 66 76 52 92
81 79 85 97 91 75 60 98 79 56
74 74 64 86 90 59 98 74 53 56
50 90 76 68 53 57 60 91 75 60
89 78 91 72 59 52 92 96 95 95
74 98 99 68 55 69 66 76 52 92
81 79 85 97 91 75 60 98 79 56

74 49 64 86 90 59 98 74 53 56
50 90 76 68 53 57 60 91 75 60
89 78 91 72 59 52 92 96 95 95
74 98 99 68 55 69 66 76 52 92
81 79 85 97 91 75 60 98 79 56
69 74 75 62 76 55 67 55 78 96
69 79 69 97 53 59 72 76 54 56
89 78 91 72 59 52 92 96 95 95
74 98 99 68 55 69 66 76 52 92
81 79 85 97 91 75 60 98 79 56

74 74 64 86 90 59 98 74 53 56
50 90 76 68 53 57 60 91 75 60
89 78 91 72 59 52 92 96 95 95
81 79 85 97 91 75 60 98 79 56
69 74 75 62 76 55 67 55 78 96
69 79 69 97 53 59 72 76 54 56
50 90 76 68 53 57 60 91 75 60
89 78 91 72 59 52 92 96 95 95
74 98 99 68 55 69 66 76 52 92
81 79 85 97 91 75 60 98 79 56


So let me explain what this means. First the 3 and 10 means 3 machines (m) and 10 jobs (n). I want to be able extract this and save it as a variable.

Then the next block shows the processing times of n number of jobs at m number of machines. I also want to put this in a variable.

After that there are m blocks of data (3 in this case) with a matrix of nxn representing setup times at each machine. I want to be able to save each of these blocks in a different variable each.

Basically I want it to show this:

A = [3 10]

PT = [81 79 85
      97 91 75
      60 98 79
      56 74 74
      64 86 90
      59 98 74
      53 56 50
      90 76 68
      53 57 60
      73 72 62]

ST1 = [69 74 75 62 76 55 67 55 78 96
       69 79 69 97 53 59 72 76 54 56
       89 78 91 72 59 52 92 96 95 95
             .
             .
             .
       81 79 85 97 91 75 60 98 79 56]

ST2 = [....]

All my files will have a different number of machines and jobs so I want MATLAB to be able to read this automatically.

ANY help is appreciated! Thank you so much and please try it!

Subject: URGENT: Read text file and save matrices

From: Diego Zegarra

Date: 13 Oct, 2008 23:13:02

Message: 2 of 8

p.d. I am not asking you to code all this for me, an explanation or a guide would be really appreciated and if you have the code that would be even better. However, ANY help is good! Thank you

Subject: URGENT: Read text file and save matrices

From: dpb

Date: 13 Oct, 2008 23:14:26

Message: 3 of 8

Diego Zegarra wrote:
> p.d. I am not asking you to code all this for me, an explanation or a
> guide would be really appreciated and if you have the code that would be
> even better. However, ANY help is good! Thank you

help iofun
help textread

--

Subject: URGENT: Read text file and save matrices

From: Walter Roberson

Date: 14 Oct, 2008 03:09:01

Message: 4 of 8

dpb <none@non.net> wrote in message <gd0l0c$s3h$1@aioe.org>...
> Diego Zegarra wrote:
> > p.d. I am not asking you to code all this for me, an explanation or a
> > guide would be really appreciated

> help iofun
> help textread

I would think textscan() would be more appropriate for
the problem than textread().

After the first two lines are read, you know the number and sizes of the additional matrices. You can construct format strings for textscan() using
FormatString = repmat('%f', 1, NumberPerLine);
and then you can apply it as

MatrixIn = textscan(fid, FormatString, NumberOfLines, ...
'CollectOutput', true);

Subject: URGENT: Read text file and save matrices

From: Andres

Date: 14 Oct, 2008 07:10:04

Message: 5 of 8

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd0klu$3ea$1@fred.mathworks.com>...
> p.d. I am not asking you to code all this for me, an explanation or a guide would be really appreciated and if you have the code that would be even better. However, ANY help is good! Thank you

Oops, this is a doubleganger thread...
But as is it urgent, I'll post my suggestion again:
Use txt2mat from the file exchange to import all the numbers first

A = txt2mat('fname.txt',0);

and then extract all your variables from A by the help of A(1,1) and A(2,1).
Regards
Andres

Subject: URGENT: Read text file and save matrices

From: Diego Zegarra

Date: 14 Oct, 2008 15:42:01

Message: 6 of 8

Hey Andres the function you are telling me (txt2mat) does not exist. What should I do?

Any extra help? Could you show me how to get at least the first matrix after the first two lines?

Thank you



"Andres " <rantore@werb.deNoRs> wrote in message <gd1gkc$a1n$1@fred.mathworks.com>...
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd0klu$3ea$1@fred.mathworks.com>...
> > p.d. I am not asking you to code all this for me, an explanation or a guide would be really appreciated and if you have the code that would be even better. However, ANY help is good! Thank you
>
> Oops, this is a doubleganger thread...
> But as is it urgent, I'll post my suggestion again:
> Use txt2mat from the file exchange to import all the numbers first
>
> A = txt2mat('fname.txt',0);
>
> and then extract all your variables from A by the help of A(1,1) and A(2,1).
> Regards
> Andres

Subject: URGENT: Read text file and save matrices

From: Barry Williams

Date: 14 Oct, 2008 19:16:02

Message: 7 of 8

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd2ek9$mfl$1@fred.mathworks.com>...
> Hey Andres the function you are telling me (txt2mat) does not exist. What should I do?
>
> Any extra help? Could you show me how to get at least the first matrix after the first two lines?
>
> Thank you
>
>
>
> "Andres " <rantore@werb.deNoRs> wrote in message <gd1gkc$a1n$1@fred.mathworks.com>...
> > "Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd0klu$3ea$1@fred.mathworks.com>...
> > > p.d. I am not asking you to code all this for me, an explanation or a guide would be really appreciated and if you have the code that would be even better. However, ANY help is good! Thank you
> >
> > Oops, this is a doubleganger thread...
> > But as is it urgent, I'll post my suggestion again:
> > Use txt2mat from the file exchange to import all the numbers first
> >
> > A = txt2mat('fname.txt',0);
> >
> > and then extract all your variables from A by the help of A(1,1) and A(2,1).
> > Regards
> > Andres
Diego,
Because you indicated that you are looking for a quick response, I'll answer for Andres. txt2mat is not a built-in MatLab function. You need to get it from the file exchange library: http://www.mathworks.com/matlabcentral/fileexchange
Search for txt2mat
Barry

Subject: URGENT: Read text file and save matrices

From: Diego Zegarra

Date: 14 Oct, 2008 20:44:02

Message: 8 of 8

Thanks Barry I got it.

"Barry Williams" <barry.r.williamsnospam@saic.com> wrote in message <gd2r5h$hd0$1@fred.mathworks.com>...
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd2ek9$mfl$1@fred.mathworks.com>...
> > Hey Andres the function you are telling me (txt2mat) does not exist. What should I do?
> >
> > Any extra help? Could you show me how to get at least the first matrix after the first two lines?
> >
> > Thank you
> >
> >
> >
> > "Andres " <rantore@werb.deNoRs> wrote in message <gd1gkc$a1n$1@fred.mathworks.com>...
> > > "Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd0klu$3ea$1@fred.mathworks.com>...
> > > > p.d. I am not asking you to code all this for me, an explanation or a guide would be really appreciated and if you have the code that would be even better. However, ANY help is good! Thank you
> > >
> > > Oops, this is a doubleganger thread...
> > > But as is it urgent, I'll post my suggestion again:
> > > Use txt2mat from the file exchange to import all the numbers first
> > >
> > > A = txt2mat('fname.txt',0);
> > >
> > > and then extract all your variables from A by the help of A(1,1) and A(2,1).
> > > Regards
> > > Andres
> Diego,
> Because you indicated that you are looking for a quick response, I'll answer for Andres. txt2mat is not a built-in MatLab function. You need to get it from the file exchange library: http://www.mathworks.com/matlabcentral/fileexchange
> Search for txt2mat
> Barry

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us