3D plot

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!

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 5 月 8 日

1 投票

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 件のコメント

Andre
Andre 2011 年 5 月 8 日
The vectors are unordered lists of (x,y) coordinates and are of the same length. They numbers are of the form 1234.123 , for two sets of coordinates to be considered equal they will have to be same down to the third decimal place.
"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?" - Yes
"If a(1),b(1) = {say} a(9),b(9) then is that to count?" - Yes
To reiterate im looking to build a third vector 'z' of the same size as the vectors A & B. This vector gives the number of A & B points that lie at the same (x,y)coordinates so that a plot3(a,b,z) shows a plot of each A & B vector with raised portions that indicate where more than one set of coordinates overlap.
Walter Roberson
Walter Roberson 2011 年 5 月 8 日
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
Andre 2011 年 5 月 9 日
Yes, [a(k),b(k)] is the k'th coordinate of that file and the density vector is intended to be cumulative across all files. my idea is to use the z coordinate(the density vector) as a means of visualizing the differences between each plot. lets say the A & B vectors correspond to a 2D plot of speed vs acceleration with each data file representing a trip. plotting a 3d trace for each file with the value of the z vector at any given point corresponding to the number of overlapping (x,y) coordinates. from this I hope to visualize which combination of speed & acceleration is favored by a particular driver.
Walter Roberson
Walter Roberson 2011 年 5 月 9 日
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
Andre 2011 年 5 月 9 日
Thanks for the answer. im not sure I understand how a_idx works.
lets say a = [1000 2000 3000 4000; 2000 3000 4000 5000]
& unique(a) = 1000
2000
3000
4000
5000
is a_idx the position of each element of unique(a) in 'a' itself???
Andre
Andre 2011 年 5 月 9 日
in the above case would a_idx be [1 2 3 4 ; 2 3 4 5]??
Walter Roberson
Walter Roberson 2011 年 5 月 9 日
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() .

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2011 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by