From: ZZ Bravo on
Hello All,

I am newbie to Matlab, and need to sort my experimental data which is in four columns

0.005 0 0.02 0
0.01 0 0.04 -0.035137518
0.015 -0.002606174 0.06 -0.109273331
0.02 -0.00986774 0.08 -0.113182424
0.025 -0.020962419 0.1 -0.157273328
0.03 -0.035070996 0.12 -0.19430221
0.035 -0.051516113 0.14 -0.224681423
0.04 -0.069678694 0.16 -0.249264962
0.045 -0.089036882 0.18 -0.268491468
0.05 -0.109134611 0.2 -0.283986291
0.055 -0.129603662 0.22 -0.296455986
0.06 -0.150050397 0.24 -0.305987793


I want to compare values in column 2nd and 4th, only for same numbers in column 1st and 3rd. In other words in first column value of 0.04 corresponds to -0.069678694, I am interested in corresponding value of 0.04 in column 4.

Columm 1st goes from 0 to 20 in steps of 0.005
Columm 3rd goes from 0 to 20 in steps of 0.02

Therefore I need to compare values in Column 2 and 4 at intervals of .02


Any advise or help, this is much appreciated!!
From: Nathan on
On Feb 23, 2:44 pm, "ZZ Bravo" <sf.i...(a)Gmail.com> wrote:
> Hello All,
>
> I am newbie to Matlab, and need to sort my experimental data which is in four columns
>
> 0.005             0                     0..02          0
> 0.01              0                     0.04    -0.035137518
> 0.015   -0.002606174    0.06    -0.109273331
> 0.02    -0.00986774     0.08    -0.113182424
> 0.025   -0.020962419    0.1     -0.157273328
> 0.03    -0.035070996    0.12    -0.19430221
> 0.035   -0.051516113    0.14    -0.224681423
> 0.04    -0.069678694    0.16    -0.249264962
> 0.045   -0.089036882    0.18    -0.268491468
> 0.05    -0.109134611    0.2     -0.283986291
> 0.055   -0.129603662    0.22    -0.296455986
> 0.06    -0.150050397    0.24    -0.305987793
>
> I want to compare values in column 2nd and 4th, only for same numbers in column 1st and 3rd. In other words in first column value of 0.04 corresponds to -0.069678694, I am interested in corresponding value of 0.04 in column 4.
>
> Columm 1st goes from 0 to 20 in steps of 0.005
> Columm 3rd goes from 0 to 20 in steps of 0.02
>
> Therefore I need to compare values in Column 2 and 4 at intervals of .02
>
> Any advise or help, this is much appreciated!!



A = [0.005 0 0.02 0
0.01 0 0.04 -0.035137518
0.015 -0.002606174 0.06 -0.109273331
0.02 -0.00986774 0.08 -0.113182424
0.025 -0.020962419 0.1 -0.157273328
0.03 -0.035070996 0.12 -0.19430221
0.035 -0.051516113 0.14 -0.224681423
0.04 -0.069678694 0.16 -0.249264962
0.045 -0.089036882 0.18 -0.268491468
0.05 -0.109134611 0.2 -0.283986291
0.055 -0.129603662 0.22 -0.296455986
0.06 -0.150050397 0.24 -0.305987793 ];
tmp = ismember(A(:,1),A(:,3));
tmp2 = ismember(A(:,3),A(:,1));
B = [A(tmp,2) A(tmp2,4)]
%%%%%%%%%%%%%%%%%%%%%%%%%%
B =
-0.00986774 0
-0.069678694 -0.035137518
-0.150050397 -0.109273331

Note, however, that this method won't work if your numbers are not
hardcoded as you have shown. If you used some form of calculating your
numbers within matlab, you will have to deal with floating point
precision tolerance.
See section 6.1 of the Matlab FAQ for more information regarding this.
http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

-Nathan
From: ZZ Bravo on
thanks Nathan, it works and I got my data sorted. Gr8!!

Nathan <ngreco32(a)gmail.com> wrote in message <aed771c5-a937-4a95-9e7f-efdbc14ecf72(a)k2g2000pro.googlegroups.com>...
> On Feb 23, 2:44 pm, "ZZ Bravo" <sf.i...(a)Gmail.com> wrote:
> > Hello All,
> >
> > I am newbie to Matlab, and need to sort my experimental data which is in four columns
> >
> > 0.005             0                     0.02          0
> > 0.01              0                     0.04    -0.035137518
> > 0.015   -0.002606174    0.06    -0.109273331
> > 0.02    -0.00986774     0.08    -0.113182424
> > 0.025   -0.020962419    0.1     -0.157273328
> > 0.03    -0.035070996    0.12    -0.19430221
> > 0.035   -0.051516113    0.14    -0.224681423
> > 0.04    -0.069678694    0.16    -0.249264962
> > 0.045   -0.089036882    0.18    -0.268491468
> > 0.05    -0.109134611    0.2     -0.283986291
> > 0.055   -0.129603662    0.22    -0.296455986
> > 0.06    -0.150050397    0.24    -0.305987793
> >
> > I want to compare values in column 2nd and 4th, only for same numbers in column 1st and 3rd. In other words in first column value of 0.04 corresponds to -0.069678694, I am interested in corresponding value of 0.04 in column 4.
> >
> > Columm 1st goes from 0 to 20 in steps of 0.005
> > Columm 3rd goes from 0 to 20 in steps of 0.02
> >
> > Therefore I need to compare values in Column 2 and 4 at intervals of .02
> >
> > Any advise or help, this is much appreciated!!
>
>
>
> A = [0.005 0 0.02 0
> 0.01 0 0.04 -0.035137518
> 0.015 -0.002606174 0.06 -0.109273331
> 0.02 -0.00986774 0.08 -0.113182424
> 0.025 -0.020962419 0.1 -0.157273328
> 0.03 -0.035070996 0.12 -0.19430221
> 0.035 -0.051516113 0.14 -0.224681423
> 0.04 -0.069678694 0.16 -0.249264962
> 0.045 -0.089036882 0.18 -0.268491468
> 0.05 -0.109134611 0.2 -0.283986291
> 0.055 -0.129603662 0.22 -0.296455986
> 0.06 -0.150050397 0.24 -0.305987793 ];
> tmp = ismember(A(:,1),A(:,3));
> tmp2 = ismember(A(:,3),A(:,1));
> B = [A(tmp,2) A(tmp2,4)]
> %%%%%%%%%%%%%%%%%%%%%%%%%%
> B =
> -0.00986774 0
> -0.069678694 -0.035137518
> -0.150050397 -0.109273331
>
> Note, however, that this method won't work if your numbers are not
> hardcoded as you have shown. If you used some form of calculating your
> numbers within matlab, you will have to deal with floating point
> precision tolerance.
> See section 6.1 of the Matlab FAQ for more information regarding this.
> http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F
>
> -Nathan