Borrar filtros
Borrar filtros

a simple clasification of matrix elements

1 visualización (últimos 30 días)
Jules Ray
Jules Ray el 18 de Oct. de 2011
dear coleages, i got a problem with some elements, i`m working with a regular rectangle vertices, so, that's what i get:
%this are the table values of a regular rectangle vertices. are showed as row and cols %as the typical notation, as you see is formed by 4 rows and two cols which %correspond to coordinates X and Y (that`s why i use the name x1, x2,... xi and also %y1, y2, ...yi for each one)
x1=p(1,1); x2=p(2,1); x3=p(3,1); x4=p(4,1); y1=p(1,2); y2=p(2,2); y3=p(3,2); y4=p(4,2);
%continuing i have got the distances between each one. As you remember this is a %rectangle, and i have just three resulting distances.
A=sqrt((x2-x1)^2+(y2-y1)^2); B=sqrt((x3-x2)^2+(y3-y2)^2); C=sqrt((x3-x4)^2+(y3-y4)^2); D=sqrt((x4-x2)^2+(y4-y2)^2); E=sqrt((x3-x1)^2+(y3-y1)^2); F=sqrt((x4-x1)^2+(y4-y1)^2); G=sqrt((x3-x1)^2+(y3-y1)^2);
%i have make some order of the obtained distances values
V=[A B C D E F G]; W=sort(V); H=W'; %max to min ordering of obtained results and transposing
%the resulting H is a table which contains the distances between each coordinates, i have charged an example rectangle and i have obtained this values:
H= 102,08 102,08 928,45 928,45 934,05 934,05 934,05
OK, HEre comes my question:
I NEED TO CREATE A SCRIPT TO:
1)ELIMINATE THE REPEATED VALUES 2)REMOVE THE MAXIMUM AND MINIMUM VALUE /OR/ JUST TAKE THE CETRAL VALUE (928,45)
THANKS FOR YOUR HELP

Respuesta aceptada

Naz
Naz el 18 de Oct. de 2011
There is one quick way to do it, however it is based on the assumption that the initial array will always have only 3 distinct values:
minV=min(H); % find min value in H
H(H==minV)=0; % set all min values to zero
maxV=max(H); % find max value in H
H(H==maxV)=0; % set all max values to zero
At this time you should have intermediate values somewhere in H. To separate them in the new matrix, you do the following:
Intermediate=H(H~=0);
This will give you the matrix with non-zero values, that is max and min values are eliminated.
If you want to get the actual value from the new H matrix you can do the following:
ind = find(H~=0, 1, 'first');
finds the address of the first non-zero value;
yourValue=H(ind)
gives the first non-zero value that is assumed to be the intermediate value between min and max.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 19 de Oct. de 2011
idxs = nchoosek(1:4,2)
H = sqrt(sum(abs(diff(reshape(p(idxs,:),size(idxs,1),[],2),1,2)).^2,3));
1.
[out1,a,b] = unique(H,'first')
2.
out2 = median(out1);

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by