filling a structure file

  • Follow


hi,
   I have a text file like,
File:
  100_at,23,45
  120_rt,56,76
  125_dr,34,23
  109_at,90,98

i want to fill this data into a structure file or in a matrix, so that i can access each data in the file. 
please help me to solve this problem.
thanks in advance....
0
Reply keyani 1/6/2011 4:36:04 AM

On 05/01/11 10:36 PM, keyani gnanapragasam wrote:

> I have a text file like,
> File:
> 100_at,23,45
> 120_rt,56,76
> 125_dr,34,23
> 109_at,90,98
>
> i want to fill this data into a structure file or in a matrix, so that i
> can access each data in the file. please help me to solve this problem.

fid = fopen('File:', 'rt');
datacell = textscan(fid, '%s%f%f', 'Delimiter', ',');
fclose(fid);

datastruct = struct('Field1', datacell{1}, 'Field2', datacell{2}, 
'Field3', datacell{3});


The result will be a structure array, one array element per row, with 
the field named "Field1" containing the initial string, the field named 
"Field2" containing the first number, and the field named "Field3" 
containing the second number.

Putting it in to a matrix requires more information from you about the 
shape you want the matrix to be, as it would be necessary to use a cell 
matrix rather than an ordinary numeric matrix.
0
Reply Walter 1/6/2011 7:45:22 AM


1 Replies
265 Views

(page loaded in 0.453 seconds)

Similiar Articles:













7/22/2012 2:34:08 PM


Reply: