How to divide elements with 4 points in triangles?

조회 수: 1 (최근 30일)
József Szabó
József Szabó 2019년 12월 7일
답변: Ralf Steinhahn 2019년 12월 7일
ele = [1 2 5 4; 2 3 6 5; 4 5 8 7; 5 6 9 8];
% ele is a matrix with 4 rows and 4 columns
% Now T shall divide each row in 2 triangles (row with three columns), where the first row gets the first three values of each element row and the second row gets the 2 last values of a element row and at least the first one.
% for example = T(1,:) = [1 2 5], T(2,:) = [5 4 1]

채택된 답변

Ralf Steinhahn
Ralf Steinhahn 2019년 12월 7일
s = size(ele,1);
T = zeros(s,3);
for i = 1:4
for j = 1:3
T(2*i-1,j) = ele(i,j);
end
for j = 3:4
T(2*i,j-2) = ele(i,j);
end
T(2*i,3) = ele(i,1);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by