이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
3D plotting of boxes using coordinates in CSV file
조회 수: 9 (최근 30일)
이전 댓글 표시
hi,
i need help on how to plot the coordinates stored in csv file in a 3D visual.
input CSV file:

expected visual:

the code im working on which is not giving th eexpected output:
채택된 답변
Voss
2023년 12월 19일
solutionData = [ ...
4 0 0 0 0 15 0 0 0 20 0 15 20 25 0 0 25 15 0 25 0 20 25 15 20; ...
2 25 0 0 25 18 0 25 0 12 25 18 12 33 0 0 33 18 0 33 0 12 33 18 12; ...
3 25 18 0 25 23 0 25 18 14 25 23 14 35 18 0 35 23 0 35 18 14 35 23 14; ...
5 25 0 12 25 12 12 25 0 30 25 12 30 47 0 12 47 12 12 47 0 30 47 12 30; ...
1 25 12 12 25 32 12 25 12 22 25 32 22 40 12 12 40 32 12 40 12 22 40 32 22];
coordinates = solutionData(:, 2:end);
N = size(coordinates,1);
colors = [0 1 0; 0 0 1; 1 0 0; 1 1 0; 1 0 1];
colors = repmat(colors,ceil(N/size(colors,1)),1);
figure
F = [1 2 4 3; 5 6 8 7; 1 2 6 5; 4 3 7 8; 2 6 8 4; 1 5 7 3];
for ii = 1:N
C = reshape(coordinates(ii, :), 3, []).';
patch( ...
'Vertices',C, ...
'Faces',F, ...
'FaceColor','flat', ...
'FaceVertexCData',colors(ii,:), ...
'FaceAlpha',0.5);
end
view(3)
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Visualization of Boxes');
grid on;
댓글 수: 24
Thulasy Chandran
2023년 12월 20일
is there any way to attach the csv file directly rather than listing the coordinates?
Voss
2023년 12월 20일
To attach the csv file here, use the paperclip button.
To read the file in your code, use readmatrix, readcell, or readtable.
I only listed the coordinates because I didn't have the file.
Thulasy Chandran
2023년 12월 20일
i have attached the file here. is it possible to do a bounding box for this?
Voss
2023년 12월 20일
Yes, you would calculate the coordinates of the bounding box and then plot it like the individual boxes are plotted.
Thulasy Chandran
2023년 12월 22일
if i want to plot the bounding box according to the box arrangement, how do i do that?
For example, something like this?

Voss
2023년 12월 22일
solutionFile = '0 - GA (20-Dec-2023 06.09.07).csv';
solutionData = readmatrix(solutionFile);
% get the two bounding box corners (min(x),min(y),min(z)) and (max(x),max(y),max(z))
p1 = min(reshape(min(solutionData(:,2:end),[],1),3,[]).',[],1);
p8 = max(reshape(max(solutionData(:,2:end),[],1),3,[]).',[],1);
coordinates = solutionData(:, 2:end);
% append the bounding box coordinates to the end of the coordinates matrix:
p_bb = [p1,p1,p1,p8,p1,p8,p8,p8];
p_bb([5 9 13]) = p8([2 3 1]);
p_bb([10 18 20]) = p1([1 3 2]);
coordinates(end+1,:) = p_bb;
N = size(coordinates,1);
colors = [0 1 0; 0 0 1; 1 0 0; 1 1 0; 1 0 1];
colors = repmat(colors,ceil(N/size(colors,1)),1);
% make the bounding box a special color:
colors(N,:) = [0.8 0.8 0.8];
figure
F = [1 2 4 3; 5 6 8 7; 1 2 6 5; 4 3 7 8; 2 6 8 4; 1 5 7 3];
for ii = 1:N
C = reshape(coordinates(ii, :), 3, []).';
patch( ...
'Vertices',C, ...
'Faces',F, ...
'FaceColor','flat', ...
'FaceVertexCData',colors(ii,:), ...
'FaceAlpha',0.5);
end
view(3)
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Visualization of Boxes');
grid on;

Thulasy Chandran
2023년 12월 23일
how do i calculate the volume of the outer container and total boxes volume?
and how to calculate the middle point of container and middle point of the box as the formula below?
distance to outer middle = Ʃ (middle point of container – middle point of box)
Voss
2023년 12월 23일
Volume is length times width times height, where length, width, and height are found by taking differences of coordinates. Middle point is average of coordinates.
Thulasy Chandran
2023년 12월 26일
may i know how to point each row by separating x,y and z coordinates to get the average coordinates?
Voss
2023년 12월 26일
solutionFile = '0 - GA (20-Dec-2023 06.09.07).csv';
T = readtable(solutionFile)
T = 5×25 table
PresentId x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 x5 y5 z5 x6 y6 z6 x7 y7 z7 x8 y8 z8
_________ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __
4 0 0 0 0 15 0 0 0 20 0 15 20 25 0 0 25 15 0 25 0 20 25 15 20
2 25 0 0 25 18 0 25 0 12 25 18 12 33 0 0 33 18 0 33 0 12 33 18 12
3 25 18 0 25 23 0 25 18 14 25 23 14 35 18 0 35 23 0 35 18 14 35 23 14
5 25 0 12 25 12 12 25 0 30 25 12 30 47 0 12 47 12 12 47 0 30 47 12 30
1 25 12 12 25 32 12 25 12 22 25 32 22 40 12 12 40 32 12 40 12 22 40 32 22
vars = T.Properties.VariableNames;
x = T{:,startsWith(vars,'x')}
x = 5×8
0 0 0 0 25 25 25 25
25 25 25 25 33 33 33 33
25 25 25 25 35 35 35 35
25 25 25 25 47 47 47 47
25 25 25 25 40 40 40 40
y = T{:,startsWith(vars,'y')}
y = 5×8
0 15 0 15 0 15 0 15
0 18 0 18 0 18 0 18
18 23 18 23 18 23 18 23
0 12 0 12 0 12 0 12
12 32 12 32 12 32 12 32
z = T{:,startsWith(vars,'z')}
z = 5×8
0 0 20 20 0 0 20 20
0 0 12 12 0 0 12 12
0 0 14 14 0 0 14 14
12 12 30 30 12 12 30 30
12 12 22 22 12 12 22 22
avg_x = mean(x,2)
avg_x = 5×1
12.5000
29.0000
30.0000
36.0000
32.5000
avg_y = mean(y,2)
avg_y = 5×1
7.5000
9.0000
20.5000
6.0000
22.0000
avg_z = mean(z,2)
avg_z = 5×1
10
6
7
21
17
Thulasy Chandran
2023년 12월 26일
can you help me with the calculation of space left and distance to outer middle as well? im finding hard to do it.
Thulasy Chandran
2023년 12월 27일
space left = outer container volume – total boxes volume
distance to outer middle = Ʃ (middle point of container – middle point of box)
Voss
2023년 12월 28일
solutionFile = '0 - GA (20-Dec-2023 06.09.07).csv';
T = readtable(solutionFile)
T = 5×25 table
PresentId x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 x5 y5 z5 x6 y6 z6 x7 y7 z7 x8 y8 z8
_________ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __
4 0 0 0 0 15 0 0 0 20 0 15 20 25 0 0 25 15 0 25 0 20 25 15 20
2 25 0 0 25 18 0 25 0 12 25 18 12 33 0 0 33 18 0 33 0 12 33 18 12
3 25 18 0 25 23 0 25 18 14 25 23 14 35 18 0 35 23 0 35 18 14 35 23 14
5 25 0 12 25 12 12 25 0 30 25 12 30 47 0 12 47 12 12 47 0 30 47 12 30
1 25 12 12 25 32 12 25 12 22 25 32 22 40 12 12 40 32 12 40 12 22 40 32 22
vars = T.Properties.VariableNames;
x = T{:,startsWith(vars,'x')};
y = T{:,startsWith(vars,'y')};
z = T{:,startsWith(vars,'z')};
dx = max(x,[],2)-min(x,[],2);
dy = max(y,[],2)-min(y,[],2);
dz = max(z,[],2)-min(z,[],2);
DX = max(x(:))-min(x(:));
DY = max(y(:))-min(y(:));
DZ = max(z(:))-min(z(:));
v = dx.*dy.*dz;
V = DX*DY*DZ;
space_left = V-sum(v)
space_left = 27440
avg_x = (max(x,[],2)+min(x,[],2))/2;
avg_y = (max(y,[],2)+min(y,[],2))/2;
avg_z = (max(z,[],2)+min(z,[],2))/2;
AVG_X = (max(x(:))+min(x(:)))/2;
AVG_Y = (max(y(:))+min(y(:)))/2;
AVG_Z = (max(z(:))+min(z(:)))/2;
D = [avg_x avg_y avg_z]-[AVG_X AVG_Y AVG_Z];
distance_to_centers = sqrt(sum(D.^2,2))
distance_to_centers = 5×1
14.7733
12.6590
11.2472
17.0953
11.0000
Thulasy Chandran
2024년 1월 2일
hi, i have question regarding the distance to centre.
avg_x avg_y avg_z - is the average coordinates of the points along the x, y, and z axes, respectively?
AVG_X AVG_Y AVG_Z - is the global center in 3D space or the centre of the outer container?
Voss
2024년 1월 2일
Yes avg_* is the center of each small box and also the average of x, y, z for each box.
Yes AVG_* is the center of the outer box and also the average of x, y, z for the outer box.
Thulasy Chandran
2024년 1월 2일
편집: Thulasy Chandran
2024년 1월 2일
for the distance to outer middle, need to find for a box and deduct it with the middle point of the outer container. This need to be done for all 5 boxes and then sum it all in the end.
distance to outer middle = Ʃ (middle point of container – middle point of box)
i tried to simulate the output for first and last generation of genetic algorithm. supposedly, the distance to centers should be lower for last generation based on the space left value but its higher.
First:
space_left =
27440
distance_to_centers =
14.7733
12.6590
11.2472
17.0953
11.0000
Last:
space_left =
24460
distance_to_centers =
19.2354
19.0066
11.6082
12.6293
22.3495
- based on the code provided, is it taking the middle point of all the boxes?
- is it possible to display the centre of the outer container and centre of one of the boxes in the visualization plot?
Voss
2024년 1월 2일
1. My code is there; you can see what it does.
If you want to sum the distances, do this:
sum(distance_to_centers)
2. Yes, add some plot call(s) where you plot the points. I'm gonna let you figure that out.
Thulasy Chandran
2024년 7월 8일
hi, how do we change this according to the datasets?
% append the bounding box coordinates to the end of the coordinates matrix:
p_bb = [p1,p1,p1,p8,p1,p8,p8,p8];
p_bb([5 9 13]) = p8([2 3 1]);
p_bb([10 18 20]) = p1([1 3 2]);
coordinates(end+1,:) = p_bb;
Thulasy Chandran
2024년 7월 9일
i would like to expand my datasets. i would like to know how can change the boundary box plotting according to it.
dataset 1:
BoxID containerWidth containerLength containerHeight
1 26 34 45
2 28 32 40
3 30 36 44
4 25 35 42
5 32 33 41
6 27 38 46
7 29 39 48
8 31 37 47
9 34 40 43
10 33 31 49
dataset 2:
BoxID containerWidth containerLength containerHeight
1 51 60 70
2 55 62 65
3 53 68 72
4 50 61 66
5 59 64 67
6 57 65 71
7 56 69 74
8 60 66 73
9 54 63 68
10 52 70 75
11 61 67 64
12 58 59 69
13 62 71 63
14 63 72 61
15 64 73 62
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

