f



How can I get the value from text file from a specific line and column?

Hi there,

How can I get the value from text file from a specific line and
column in MATLAB?

For example, Hello.txt

00001 38 49 50 61 72
00002 12 23 45 56
00003 12 45 89 32 98 78
00004 23 45 78
00005 12 45 89 98
00006 22 1 2 3

I want a value from line 3 column 4 which is 89 to be a variable in
workspace. What should I do? And also for a whole line and whole
column too.

Thx
0
Ong_Mamma (7)
3/6/2005 11:44:52 AM
comp.soft-sys.matlab 211265 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

7 Replies
435 Views

Similar Articles

[PageSpeed] 33

This is an example only, actually my data is bigger than this. The
number of data in each line, is not equal.
0
Ong_Mamma (7)
3/6/2005 12:00:21 PM
Hi,

it's quiet easy if the text file contains only numeric data :

[A]=textread('hello.txt','');

% value from line 3 column 4 which is 89
A(3,4)

% a whole line
A(3,:)

% whole column too
A(:,4)
A(:,7)

0 will be return for empty values
J�r�me
0
dutmatlab (3797)
3/7/2005 7:48:39 AM
Thx Jerome,

One more question. If my text file also contains string. What should
I do

hello.txt
----------------------------
Test Test
123456 1 2 3 2 1
456789 1 5 6 2 3 3
893151 2 3 3 2
567896 2 1 8 3
AAAAAA 1 2
----------------------------

Thx

J�r�me wrote:
>
>
> Hi,
>
> it's quiet easy if the text file contains only numeric data :
>
> [A]=textread('hello.txt','');
>
> % value from line 3 column 4 which is 89
> A(3,4)
>
> % a whole line
> A(3,:)
>
> % whole column too
> A(:,4)
> A(:,7)
>
> 0 will be return for empty values
> J�r�me
0
Ong_Mamma (7)
3/7/2005 10:07:39 AM
Thx Jerome,

One more question. If my text file also contains string. What should
I do

hello.txt
----------------------------
Test Test
123456 1 2 3 2 1
456789 1 5 6 2 3 3
893151 2 3 3 2
567896 2 1 8 3
AAAAAA 1 2
----------------------------

Thx

J�r�me wrote:
>
>
> Hi,
>
> it's quiet easy if the text file contains only numeric data :
>
> [A]=textread('hello.txt','');
>
> % value from line 3 column 4 which is 89
> A(3,4)
>
> % a whole line
> A(3,:)
>
> % whole column too
> A(:,4)
> A(:,7)
>
> 0 will be return for empty values
> J�r�me
0
Ong_Mamma (7)
3/7/2005 10:07:42 AM
[A,B,C,D,E,F,G]=textread('text.txt','%s%s%s%s%s%s%s');

G{end+1}='';

M=[A B C D E F G]

M{3,4}

X=char(M{7,:})

J�r�me
0
dutmatlab (3797)
3/7/2005 11:22:26 AM
Thx again

This is only for know the specific number of column. But what if i do
not know how many column is?

Ong

J�r�me wrote:
>
>
> [A,B,C,D,E,F,G]=textread('text.txt','%s%s%s%s%s%s%s');
>
> G{end+1}='';
>
> M=[A B C D E F G]
>
> M{3,4}
>
> X=char(M{7,:})
>
> J�r�me
0
Ong_Mamma (7)
3/7/2005 12:06:20 PM
Let's say, My file is contained not only number but also string too.
And I don't know the exactly number of column.

00001 38 49 50 61 72
00002 12 23 45 56
00003 12 45 89 32 98 78
00004 23 45 78
00005 12 45 89 98
00006 22 1 2 3
0000A 35 1 3 5
00009 66 5 4 8 02

And I want a line which has 0000A at the beginning of the line . And
I want an output to be

X = ['0000A'; '35';'1';'3';'5']

Thank you very much

J�r�me wrote:
>
>
> [A,B,C,D,E,F,G]=textread('text.txt','%s%s%s%s%s%s%s');
>
> G{end+1}='';
>
> M=[A B C D E F G]
>
> M{3,4}
>
> X=char(M{7,:})
>
> J�r�me
0
Ong_Mamma (7)
3/7/2005 12:28:13 PM
Reply: