Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / MATLAB / July 2008



Tip: Looking for answers? Try searching our database.

Find value in an array/matrix

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hany R. - 17 Jul 2008 00:09 GMT
Hi all

I was wondering if there is a way to search within a matrix
of 2x10
This search would point out a value which has
repeated within the same row 3 times. This value
could have a variation of +/-0.5. The output of the
system would be the average of these three values.
thought of using a coulple of if conditions, but I'm
not sure how to start.
Any suggestions are appreciated
Matt Fig - 17 Jul 2008 00:32 GMT
This value
> could have a variation of +/-0.5.

A little clearing up... Do you mean that the values should
be the same within .5 or that on different arrays, the
values would vary.  Maybe provide an example array and what
you expect the function to return when it operates on the array.
Hany R. - 18 Jul 2008 13:03 GMT
"Matt Fig" <spamanon@yahoo.com> wrote in message
<g5m0di$muk$1@fred.mathworks.com>...
> This value
> > could have a variation of +/-0.5.
[quoted text clipped - 3 lines]
> values would vary.  Maybe provide an example array and what
> you expect the function to return when it operates on the array.

A)
Example:
Matrix=[89.5  90  75   23   80  90.2  24  -1  5  101;
       44    34  22   -10  43  46    90  2   15 48]

output would be: [89.5 90 90.2; 44 34 46]
then I would average each row and get the x,y coordinates
Hany R. - 18 Jul 2008 13:20 GMT
"Hany R." <hr211@bath.ac.uk> wrote in message
<g5q0pm$hr6$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message
> <g5m0di$muk$1@fred.mathworks.com>...
[quoted text clipped - 14 lines]
> output would be: [89.5 90 90.2; 44 34 46]
> then I would average each row and get the x,y coordinates

Additional:

the system would work like this
-the first row is searched and averaged
-second row is searched and averaged
-in case that there are to sets with similarities (
89.5 90 90.2 and 77 77.4 76.8 in the same row)
a seperate array or a third row is going to be there.
(i'm still working on the algorithm).
Each value in this third row is considered the amplitude
for both the first and second column, the higher value
in the third row, the more likely the x,y values are correct
and hence should be chosen.
Example: for the above
     89.5 90 90.2      77 77.4 76.8
Amp:  .2   .1  .5       .01 .02  .3
the first set is chosen (the left hand side i.e. 89.5,...)

Thank you
Peter Boettcher - 18 Jul 2008 14:25 GMT
> "Hany R." <hr211@bath.ac.uk> wrote in message
> <g5q0pm$hr6$1@fred.mathworks.com>...
[quoted text clipped - 36 lines]
>
> Thank you  

Try to start with something simple.  loop through each element, and test
the distance to each of the other elements.  Compare that distance to
your threshold value, and count the number that match.  If that number
of matches meets your criteria for a cluster, then you're done!  Output
the indices, or average the answers, or whatever you want to do.

In other words, no one can write the code for you, because the problem
specification is still somewhat vague.  That's ok, you're still trying
to figure it out.  But the best way to figure it out is to start trying
algorithms, writing simple loopy code, until it does what you want.

That loopy code can then be used as a description of what you want to
do, and we can then help improve the code, vectorize it, simplify it,
whatever.

-Peter
Hany R. - 22 Jul 2008 20:28 GMT
Hi,

well, for simplicity, I'm putting part of the code
here..where the output is completely correct..
--------------------------------------------------------
FINALMATRIX=[10.1,10.2,5.1,5.2,10.3,5.3,100,55,90,5.4]

idx1=1;
idx2=1;
   for ii=1:9; % they are 10 columns, but its covered
by 'if' statement
       eachelem=ii+1;
       for secondrow=1:10  % to compare each element
           if eachelem>=11 break; %so it include the 10th
           end
           
           if (abs((FINALMATRIX(1,ii))-(FINALMATRIX
(1,eachelem)))) <= 1 % 1m instead of the 0.5 earlier
              CollectA(1,idx1)=[FINALMATRIX(1,eachelem)];
              idx1=idx1+1; %takes each value except the
original
              if secondrow==1;
                  CollectA(1,idx1)=[FINALMATRIX(1,ii)]; %
adds up the original element
                  idx1=idx1+1;
              end

           end % if calculation
           eachelem=eachelem+1;
       end % secondrow
   end % if ii (columns)
---------------------------------------------------------
the output should be [10.1, 10.2, 10.3, 5.1, 5.2, 5.3,5.4]
(the order is not an issue..  I'm getting all the values,
but some are repeated more than once, so instead of having
7 outputs, I'm getting 11

I'm not sure if the error is from the 'break' command
Thanks
Walter Roberson - 17 Jul 2008 00:46 GMT
>I was wondering if there is a way to search within a matrix
>of 2x10
>This search would point out a value which has
>repeated within the same row 3 times. This value
>could have a variation of +/-0.5.

Peter Boettcher <boettcher@ll.mit.edu>
already replied to your earlier identical question, requesting
that you clarify the question. Please respond with your clarifications
rather than posting the same unclear question again.
Signature

 "Do not wait for leaders. Do it alone, person to person."
                                             -- Mother Teresa

Peter Boettcher - 17 Jul 2008 16:10 GMT
> Hi all
>
[quoted text clipped - 6 lines]
> thought of using a coulple of if conditions, but I'm
> not sure how to start.

I assume you did not notice my response to your first posting.  Please
go look for it, read it, and respond under that thread.

-Peter
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.