Thread Subject: Better way to read data

Subject: Better way to read data

From: Pete sherer

Date: 17 Jun, 2008 21:40:18

Message: 1 of 2

Hi,

I used the following codes to read the variable tmp which is
a char type variable.
tmp(1,:)='1,2,3,4,5,6,7';
tmp(2,:)='3,4,5,6,7,8,9';
tmp(3,:)=' ,1,2,3,4,5,6';

(Note that orginally data shown in tmp is a cell type. I
however change it to be char type because strread accept
only char type variable)

I can only read it line-by-line.
for ii = 1:3
[a1(ii,1),a2(ii,1),a3(ii,1),a4(ii,1),a5(ii,1),a6(ii,1),a7(ii,1)]
= strread( tmp(ii,:), '%u %u %u %u %u %u %u', 1,
'delimiter', ',');
end

How can I vectorize the above codes?
Thanks a lot for your suggestions.
Pete

Subject: Better way to read data

From: us

Date: 17 Jun, 2008 22:00:17

Message: 2 of 2

"Pete sherer":
<SNIP wants to read his/her cells...

one of the many solutions

% the data
     c={
          '1,2,3'
          '10,20,30,40'
          '-1,-2'
     };
% the engine
     opt={'delimiter',','};
     r=cellfun(@(x) strread(x,'%n',opt{:}).',c,'uni',false)
% the result
     r{:}
%{
     ans = 1 2 3
     ans = 10 20 30 40
     ans = -1 -2
%}

us

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 17 Jun, 2008 18:05:06
cell us 17 Jun, 2008 18:05:06
strread us 17 Jun, 2008 18:05:06
cellfun us 17 Jun, 2008 18:05:06
rssFeed for this Thread

Contact us at files@mathworks.com