Mostrar comentarios más antiguos
Hey,
so heres my problm. I have multiple files each of which contains 2 different vectors - a and b. I need to compare all the vectors so that whenever the point represented by the intersection of vector a and b is repeated between files I want to increment the value of a third vector by one. I will then use the third vector as the z axis in a plot of a and b. the idea is to create a 3d plot of the density of intersecting points in each file.
example
for i = 1:length(files)
avalues.(files{i}) = (files{i}.a);
bvalues.(files{i}) = (files{i}.b);
end
comparing all the a & b values in the new structure I would like to create a 'density vector' the same length as the a & b vectors that indicates the number of intersecting points between a & b. so if a(1), b(1) = a(2),b(2) the density vector at that point should read 1 and be incremented once for each identical point.
thanks in advance!
Respuestas (1)
Walter Roberson
el 8 de Mayo de 2011
1 voto
I am not clear about what your data is. Are the vectors lists of (x,y) or (x,y,z) coordinates? Or is each vector a single multidimensional directional vector? Or are the vectors ordered lists of single-dimensional coordinates ??
When you talk about intersection, are you talking about interpreting each of the vectors as lists of points and looking for points that are the same? Or do you mean that adjacent points in each of the vectors imply an edge and you are looking for crossing edges?
If a(1),b(1) = {say} a(9),b(9) then is that to count?
Are these coordinates integers? If not then what tolerance should be used for the comparison?
Are the vectors the same length in each of the files?
7 comentarios
Andre
el 8 de Mayo de 2011
Walter Roberson
el 8 de Mayo de 2011
To confirm, [a(K),b(K)] is the K'th (x,y) coordinate for that file?
Is the density vector cumulative across all of the files? Are all of the A/B vectors to be plotted on the same plot? If so, then are they to be somehow offset from each other?
Andre
el 9 de Mayo de 2011
Walter Roberson
el 9 de Mayo de 2011
Okay then... read all of the files first.
Extract all of the "a" values for all of the files simultaneously, multiply the list of them by 1000, round() to get integers, and run unique() on the list in its multi-output form. You need to get out unique values and the indices in to the vector of unique values (so two entries would have the same indices if and only if they are unique integers after multiplying by 1000.) Call this a_idx.
Same processing for "b" to get a second list of unique values and the second list of indices per entry, b_idx.
Now if nua and nub are corresponding length() of the lists of unique _values_ (not indices), then:
density_map = accumarray([a_idx(:),b_idx(:)], 1, [nua, nub]);
Let ua and ub be the lists of unique values output by unique. Divide them by 1000 at this point, as you now need them back in their 3-decimal-place form.
Then for each individual line,
for N = 1 : numfiles
st = 1 + (N-1)*VecLength; en = N * VecLength;
these_a = a_idx(st:en);
these_b = b_idx(st:en);
these_z = density_map(sub2idx([nua,nub], these_a, these_b));
plot3( ua(these_a), ub(these_b), these_z );
end
Andre
el 9 de Mayo de 2011
Andre
el 9 de Mayo de 2011
Walter Roberson
el 9 de Mayo de 2011
You want a_idx to be the position of each element of "a" within the vector of unique(a) values. This corresponds to the _third_ output of unique() .
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!