From: Francki on
Hi guys,

basically I've some data in a text file called "Raw Data". Raw Data has the following data:

BUT IN/OUT 1 12 34.4
JON IN 2 13 35.67
GER IN/OUT 3 14 98.8
GRO OUT 4 15 67.6
FRE OUT 5 16 45.0
TRE IN 6 17 67.03
PIU IN/OUT 7 18 78.46

Now I have a code that reads this data. Upon reading i want matlab to return in a matrix form the names and numbers of all those that have 'OUT' or 'IN/OUT'. say something like this:

GER 3 14 98.8
GRO 4 15 67.6
FRE 5 16 45.0
PIU 7 18 78.46
BUT 1 12 34.4

or in seperate matrices:

3 14 98.8 GER
4 15 67.6 GRO
num = 5 and lap= 16 and time= 45.0 and name= FRE
7 18 78.46 PIU
1 12 34.4 BUT


here is the code i've got:

file=importdata('RawData.txt');

d=file.textdata;
r=[d(:,1) d(:,2)];
a=file.data;
z=[a(:,1) a(:,2) a(:,3)];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%record data%%%%%%%%%%%%

for i=1:length(d(:,2))

cp= strcmp(char(r(i,2)),'OUT');cp1= strcmp(char(r(i,2)),'OUT/IN');
cp2= strcmp(char(r(i,2)),'IN');

if cp==1 || cp1==1

stoplapout=z(i,2);
outlapt=z(i,3)%%%outlap

elseif cp2==1 || cp1==1

carnum=z(i,1); %%%%carnumber
driver=r(i,1);%%%%%driver
stoplap=z(i,2);%%%%stop lap
inlapt=z(i,3); %%%%inlap
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

matlab returns the right values but doesn't assemble data into matrix form (all it does is i.e.carnum=1; carnum=3; carnum=5, etc.....

Can anyone help me get around this pesky problem?.....all help are massively appreciated.
From: us on
"Francki " <jonesfranckandi(a)yahoo.fr> wrote in message <i3ce40$mjb$1(a)fred.mathworks.com>...
> Hi guys,
>
> basically I've some data in a text file called "Raw Data". Raw Data has the following data:
>
> BUT IN/OUT 1 12 34.4
> JON IN 2 13 35.67
> GER IN/OUT 3 14 98.8
> GRO OUT 4 15 67.6
> FRE OUT 5 16 45.0
> TRE IN 6 17 67.03
> PIU IN/OUT 7 18 78.46
>
> Now I have a code that reads this data. Upon reading i want matlab to return in a matrix form the names and numbers of all those that have 'OUT' or 'IN/OUT'. say something like this:
>
> GER 3 14 98.8
> GRO 4 15 67.6
> FRE 5 16 45.0
> PIU 7 18 78.46
> BUT 1 12 34.4
>
> or in seperate matrices:
>
> 3 14 98.8 GER
> 4 15 67.6 GRO
> num = 5 and lap= 16 and time= 45.0 and name= FRE
> 7 18 78.46 PIU
> 1 12 34.4 BUT
>
>
> here is the code i've got:
>
> file=importdata('RawData.txt');
>
> d=file.textdata;
> r=[d(:,1) d(:,2)];
> a=file.data;
> z=[a(:,1) a(:,2) a(:,3)];
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> %%%%%%record data%%%%%%%%%%%%
>
> for i=1:length(d(:,2))
>
> cp= strcmp(char(r(i,2)),'OUT');cp1= strcmp(char(r(i,2)),'OUT/IN');
> cp2= strcmp(char(r(i,2)),'IN');
>
> if cp==1 || cp1==1
>
> stoplapout=z(i,2);
> outlapt=z(i,3)%%%outlap
>
> elseif cp2==1 || cp1==1
>
> carnum=z(i,1); %%%%carnumber
> driver=r(i,1);%%%%%driver
> stoplap=z(i,2);%%%%stop lap
> inlapt=z(i,3); %%%%inlap
> end
> end
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> matlab returns the right values but doesn't assemble data into matrix form (all it does is i.e.carnum=1; carnum=3; carnum=5, etc.....
>
> Can anyone help me get around this pesky problem?.....all help are massively appreciated.

there are many things that should be improved, eg,

d=file.textdata;
r=[d(:,1) d(:,2)]; % <- R == D == FILE.TEXTDATA...
a=file.data;
z=[a(:,1) a(:,2) a(:,3)]; % <- Z == A == FILE.DATA...

now, for your first example...

one of the solutions

fnam='foo.txt'; % <- your file name...
d=importdata(fnam);
ix=ismember(d.textdata(:,2),{'OUT','IN/OUT'});
r=[d.textdata(ix,1),num2cell(d.data(ix,:))]
%{
% r =
'BUT' [1] [12] [ 34.4] % <- note: arrangement differs...
'GER' [3] [14] [ 98.8]
'GRO' [4] [15] [ 67.6]
'FRE' [5] [16] [ 45]
'PIU' [7] [18] [78.46]
%}
% look at the second output of ISMEMBER to see how you can improve the
% rest of your code...
[ix,ix]=ismember(d.textdata(:,2),{'OUT','IN/OUT','IN'});
disp(ix.');
% 2 3 2 1 1 3 2 % <- index into template(!)...

us
From: Francki on
"us " <us(a)neurol.unizh.ch> wrote in message <i3cfis$q9r$1(a)fred.mathworks.com>...
> "Francki " <jonesfranckandi(a)yahoo.fr> wrote in message <i3ce40$mjb$1(a)fred.mathworks.com>...
> > Hi guys,
> >
> > basically I've some data in a text file called "Raw Data". Raw Data has the following data:
> >
> > BUT IN/OUT 1 12 34.4
> > JON IN 2 13 35.67
> > GER IN/OUT 3 14 98.8
> > GRO OUT 4 15 67.6
> > FRE OUT 5 16 45.0
> > TRE IN 6 17 67.03
> > PIU IN/OUT 7 18 78.46
> >
> > Now I have a code that reads this data. Upon reading i want matlab to return in a matrix form the names and numbers of all those that have 'OUT' or 'IN/OUT'. say something like this:
> >
> > GER 3 14 98.8
> > GRO 4 15 67.6
> > FRE 5 16 45.0
> > PIU 7 18 78.46
> > BUT 1 12 34.4
> >
> > or in seperate matrices:
> >
> > 3 14 98.8 GER
> > 4 15 67.6 GRO
> > num = 5 and lap= 16 and time= 45.0 and name= FRE
> > 7 18 78.46 PIU
> > 1 12 34.4 BUT
> >
> >
> > here is the code i've got:
> >
> > file=importdata('RawData.txt');
> >
> > d=file.textdata;
> > r=[d(:,1) d(:,2)];
> > a=file.data;
> > z=[a(:,1) a(:,2) a(:,3)];
> >
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> >
> > %%%%%%record data%%%%%%%%%%%%
> >
> > for i=1:length(d(:,2))
> >
> > cp= strcmp(char(r(i,2)),'OUT');cp1= strcmp(char(r(i,2)),'OUT/IN');
> > cp2= strcmp(char(r(i,2)),'IN');
> >
> > if cp==1 || cp1==1
> >
> > stoplapout=z(i,2);
> > outlapt=z(i,3)%%%outlap
> >
> > elseif cp2==1 || cp1==1
> >
> > carnum=z(i,1); %%%%carnumber
> > driver=r(i,1);%%%%%driver
> > stoplap=z(i,2);%%%%stop lap
> > inlapt=z(i,3); %%%%inlap
> > end
> > end
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> >
> > matlab returns the right values but doesn't assemble data into matrix form (all it does is i.e.carnum=1; carnum=3; carnum=5, etc.....
> >
> > Can anyone help me get around this pesky problem?.....all help are massively appreciated.
>
> there are many things that should be improved, eg,
>
> d=file.textdata;
> r=[d(:,1) d(:,2)]; % <- R == D == FILE.TEXTDATA...
> a=file.data;
> z=[a(:,1) a(:,2) a(:,3)]; % <- Z == A == FILE.DATA...
>
> now, for your first example...
>
> one of the solutions
>
> fnam='foo.txt'; % <- your file name...
> d=importdata(fnam);
> ix=ismember(d.textdata(:,2),{'OUT','IN/OUT'});
> r=[d.textdata(ix,1),num2cell(d.data(ix,:))]
> %{
> % r =
> 'BUT' [1] [12] [ 34.4] % <- note: arrangement differs...
> 'GER' [3] [14] [ 98.8]
> 'GRO' [4] [15] [ 67.6]
> 'FRE' [5] [16] [ 45]
> 'PIU' [7] [18] [78.46]
> %}
> % look at the second output of ISMEMBER to see how you can improve the
> % rest of your code...
> [ix,ix]=ismember(d.textdata(:,2),{'OUT','IN/OUT','IN'});
> disp(ix.');
> % 2 3 2 1 1 3 2 % <- index into template(!)...
>
> us

It's not exactly what I'm looking for but thanks.....I can take it from here on.

Safe
From: us on
"Francki "
> It's not exactly what I'm looking for but thanks.....I can take it from here on.
>
> Safe

just to be sure: the snippet certainly reproduces your first example...
did you tell the whole story(?)...

us
From: Francki on
"us " <us(a)neurol.unizh.ch> wrote in message <i3ciu2$t65$1(a)fred.mathworks.com>...
> "Francki "
> > It's not exactly what I'm looking for but thanks.....I can take it from here on.
> >
> > Safe
>
> just to be sure: the snippet certainly reproduces your first example...
> did you tell the whole story(?)...
>
> us

Sorry for the late reply but I have another favour....is it possible for your code to be modified so that the computer of those who don't have "in" into that matrix and replacing it by zero....like this:
'BUT' [1] [12] [ 34.4]
'BUT' [1] [12] [0]
'GER' [3] [14] [ 98.8]
'GER' [3] [14] [ 0]
'GRO' [4] [15] [ 67.6]
'GRO' [4] [15] [0]
'FRE' [5] [16] [ 45]
'FRE' [5] [16] [ 0]
'PIU' [7] [18] [78.46]
'PIU' [7] [18] [0]

any help would be greatly appreciated!!.