determine elements belonging to the same group and change coordinates
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes

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
darova
on 28 Aug 2019
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
Ana Bermejo Jimenez
on 29 Aug 2019
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.
Ana Bermejo Jimenez
on 29 Aug 2019
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
darova
on 29 Aug 2019
I saw, sorry for misunderstanding
Try this
Ana Bermejo Jimenez
on 29 Aug 2019
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
darova
on 29 Aug 2019
You pick some z level and a pile should be straightened to (x,y)? You mean this?

Ana Bermejo Jimenez
on 29 Aug 2019
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.
darova
on 29 Aug 2019
Are piles always straight?
Ana Bermejo Jimenez
on 29 Aug 2019
Yes they are.
darova
on 29 Aug 2019
Current script for piles that are always straight
Ana Bermejo Jimenez
on 30 Aug 2019
it works fine thank you!
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
See Also
on 28 Aug 2019
on 30 Aug 2019
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)