determine elements belonging to the same group and change coordinates

Capture.JPG
clc
clear all
M = dlmread('C:\Users\wexample_case2.txt','\t',1);%%change path
element = M(:,1);
xs = M(:,2);
xe = M(:,3);
ys = M(:,4);
ye = M(:,5);
zs = M(:,6);
ze = M(:,7);
%%
for i=1:length(element-1)
if xe(i)==xs(i+1) && ye(i)==ys(i+1)
xs(i+1)=xs(i);
ys(i+1)=ys(i);
xe(i)=xs(i);
ye(i)=ys(i);
xs1=xs;
elseif xs(i)==xe(i-1) && ys(i)==ye(i-1)
xe(i)=xs(i-1)
ye(i)=ys(i-1)
else
xe(i)=xs(i)
end
end

 Accepted Answer

Just loop through elements
clc,clear
A = load('wexample_case2.txt');
x = A(:,2:3);
y = A(:,4:5);
z = A(:,6:7);
for i = 1:3:size(x,1)
j = (0:2) + i;
x(j,:) = x(i,1);
y(j,:) = y(i,1);
end
plot3(x',y',z','.-r')
xlim([0 7])
ylim([0 6])

10 Comments

Hi Darova,
Thank you for your answer. It works but only if the elements are in order as I gave them to you. How would this be if the elements were scattered as in the file attached?
Thanks in advance.
Ana.
It is the same numbers but I switched a couple of rows so the elements are not in order
element n xstart xend ystart yend zstart zend
1 1 1 1 1 0 1
2 1 1 1 1 1 2
3 1 1 1 1 2 3
4 6.5 6.75 1 1 2 3
5 2 2 1.25 1.5 1 2
6 2 2 1.5 1.75 2 3
7 3 3.25 1 1 0 1
8 3.25 3.5 1 1 1 2
9 1 1 5 5 2 3
10 1 1 5 5 0 1
11 1 1 5 5 1 2
12 3.5 3.75 1 1 2 3
13 2 2 5 5 0 1
14 2 2 5 5 1 2
15 2 2 5 5 2 3
16 3 3.25 5 5 0 1
17 3.25 3.5 5 5 1 2
18 3.5 3.75 5 5 2 3
19 6 6.25 1 1 0 1
20 6.25 6.5 1 1 1 2
21 2 2 1 1.25 0 1
I saw, sorry for misunderstanding
Try this
It works perfectly, thank you so much! You are a diamond!
One last question. If I wanted to use the x y coordinates of a given z level should I just change
ind = find(zs<min(zs)+0.1)
for something like
for i=1:length(zs)
[ind(i,1) p1(i,1)]= min(abs(selected_z_value-zs(i,1)))
end
You pick some z level and a pile should be straightened to (x,y)? You mean this?
2Untitled.png
Yes that's correct. I was trying to pick a level defined by an element zstart or zend. But ideally would be a random level.
Current script for piles that are always straight

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!