Clear Filters
Clear Filters

Create a matrix of element (lines) points connectivity

6 views (last 30 days)
Hi,
I am new to matlab trying to create a matrix as attached in the code below
clear all;
clc
nelments = 3;
nelments_vec = 1:nelments;
npoint = 5;
connect = zeros(nelments,npoint); % INTIALIZE ELEMENT CONNECTIVITY
for i=1:nelments
for j=1:npoint
connect(i,j)=[nelments_vec(i) nelments_vec(i)+1]; % ELEMENT/pointCONNECTIVITY MATRIX I WOULD LIKE TO OBTAIN
end
end
The answer should be
connect =[1 2 3 4 5;
5 6 7 8 9;
9 10 11 12 13]
How could I obtain such matrix with different values of npoint and nelments ???
I wish anyone could help me !!!!

Accepted Answer

Matt J
Matt J on 1 Jul 2021
Edited: Matt J on 1 Jul 2021
nelments = 3;
npoint = 5;
connect=(1:npoint) + (npoint-1)*(0:nelments-1).'
connect = 3×5
1 2 3 4 5 5 6 7 8 9 9 10 11 12 13

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!