Copy Values of a row to another row, when two values are the same

3 Ansichten (letzte 30 Tage)
deguchi
deguchi am 21 Mai 2019
Bearbeitet: deguchi am 21 Mai 2019
Hey,
I got a question, first the source code:
for m=1:elements
elTable(m,1)=input('Elementnummer:');
elTable(m,2)=input('Anfangsknoten des Elements');
elTable(m,3)=input('Endknoten des Elements');
if any(elTable(:,2)==elTable(m,2))
index=find(any(elTable(:,2)==elTable(m,2)))
elTable(m,4:6)=elTable(index,4:6)
else
elTable(m,4)=input('x-Koordinate des Startknotens:');
elTable(m,5)=input('y-Koordinate des Startknotens:');
elTable(m,6)=input('z-Koordinate des Startknotens:');
end
if any(elTable(:,3)==elTable(m,3))
index=find(any(elTable(:,3)==elTable(m,3)))
elTable(m,7:9)=elTable(index,7:9)
else
elTable(m,7)=input('x-Koordinate des Endknotens:');
elTable(m,8)=input('y-Koordinate des Endknotens:');
elTable(m,9)=input('z-Koordinate des Endknotens:');
end
end
Okay, this is a element table for a 3D Frame System used for FEM calculations.
Rows contain: Number of the element, Number of the first node of the element, number of the last node of the element, x-,y-,z- coordinate of the first node, x-,y-,z- coordinate of the last node
For example: 1, 1, 2, 0, 0, 0, 3, 0, 0
2, 1, 3, 0, 0, 0, 0, -4, 0
As you can see, element 2 has the same "first node" as element 1. Therefore it would be great when I just could copy x1,y1,z1 of element 1 to the second row instead of entering the coordinates again. (Sometimes one node belongs to 4 or more elements and you could save time not entering the coordinates again and again).
My Idea was to compare if there is any entry in column 2 (or 3, depending on which coordinates you want to copy) that is the same as the entry you want to compare and to tell matlab then to copy the related values from one row to another.
The source code above was my solution. But when I try so, Matlab is only asking for element numer, and the node numbers. So whats wrong about the code?
Best regards

Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by