rearrange matrix to vector according to adress

1 view (last 30 days)
hi
i have a matrix CHARGE with value coresponding like this
CHARGE =[178.4 0.78 0 0 0 0 0 0
0 0 0 0 154.9 88.54 666.67 178.6
154.1 89.89 0 0 0 0 0 0
0 0 0 0 89.89 154.1 488 488
88.54 154.9 0 0 0 0 0 0
0 0 0 0 0.78 178.4 178.6 666.67
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 ]
line1 is a charge value of x ... x(M(1,1)) x(M(1,2)) x(M(1,3)) x(M(1,4)) x(M(1,5)) x(M(1,6)) x(M(1,7)) x(M(1,8))
line2 is a charge value of y ... y(M(1,1)) y(M(1,2)) y(M(1,3)) y(M(1,4)) y(M(1,5)) y(M(1,6)) y(M(1,7)) y(M(1,8))
line3 is a charge value of x ... x(M(2,1)) x(M(2,2)) x(M(2,3)) x(M(2,4)) x(M(2,5)) x(M(2,6)) x(M(2,7)) x(M(2,8))
line4 is a charge value of y ... y(M(2,1)) y(M(2,2)) y(M(2,3)) y(M(2,4)) y(M(2,5)) y(M(2,6)) y(M(2,7)) y(M(2,8))
line5 is a charge value of x ... x(M(3,1)) x(M(3,2)) x(M(3,3)) x(M(3,4)) x(M(3,5)) x(M(3,6)) x(M(3,7)) x(M(3,8))
line6 is a charge value of y ... y(M(3,1)) y(M(3,2)) y(M(3,3)) y(M(3,4)) y(M(3,5)) y(M(3,6)) y(M(3,7)) y(M(3,8))
etc..
witch M is matrix adress
M = [ 1 8 12 13 14 9 3 2
3 9 14 15 16 10 5 4
5 10 16 17 18 11 7 6
12 19 23 24 25 20 14 13
14 20 25 26 27 21 16 15
16 21 27 28 29 22 18 17
23 30 34 35 36 31 25 24
25 31 36 37 38 32 27 26
27 32 38 39 40 33 29 28
34 41 45 46 47 42 36 35
36 42 47 48 49 43 38 37
38 43 49 50 51 44 40 39 ]
and i want to make all value of charge in one column VFC
i use reshape but is not give me what i wont
i use loop like this but its make me crazy
NE=length(CHARGE(:,1))
NNode=51;
VFC=zeros(NNode*2,1) ;
for i=1:NNode*2
for j=1:length(M)
CHARGE( M(i,j),j)=CHARGE( M(i,j),j)+ ?........ %(i need to some value of charge for the same adrees in M )
VFC(i*2-1)=CHARGE( M(i,j),j) +......? % (i*2-1 for value of x)
VFC(i*2)= .......? %(i*2 for value of y
end
end
i feel its just simple but
but what i want is to reanrange my matrix to a vector with additional value of Matrix CHARGE in the same adress of Matrix M
i do it manualy with excel
but it took me alot of time
another word
i need this vector
VFC =[ 178.4
0
0
178.6
154.1
666.7
0
488
88.54
488
0
666.7
0
178.4
0.78
0
89.89
88.54
154.9
154.1
0
0.78
0
0
0
0
0
154.9
0
0
0
89.89
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0]
can someone help me
  2 Comments
Arif Hoq
Arif Hoq on 31 Mar 2022
Edited: Arif Hoq on 31 Mar 2022
CHARGE =[178.4 0.78 0 0 0 0 0 0
0 0 0 0 154.9 88.54 666.67 178.6
154.1 89.89 0 0 0 0 0 0
0 0 0 0 89.89 154.1 488 488
88.54 154.9 0 0 0 0 0 0
0 0 0 0 0.78 178.4 178.6 666.67
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 ] ;
VFC=CHARGE(:); % Matric CHARGE in 1 column
is that your expectation ??
if now then can you please explain again ?
i do it manualy with excel
can you plese show us that ?
alize beemiel
alize beemiel on 31 Mar 2022
i try this
and its give me what i want
MCNT = [ 1 8 12 13 14 9 3 2
3 9 14 15 16 10 5 4
5 10 16 17 18 11 7 6
12 19 23 24 25 20 14 13
14 20 25 26 27 21 16 15
16 21 27 28 29 22 18 17
23 30 34 35 36 31 25 24
25 31 36 37 38 32 27 26
27 32 38 39 40 33 29 28
34 41 45 46 47 42 36 35
36 42 47 48 49 43 38 37
38 43 49 50 51 44 40 39 ];
CHARGE =[178.4 0.78 0 0 0 0 0 0
0 0 0 0 154.9 88.54 666.67 178.6
154.1 89.89 0 0 0 0 0 0
0 0 0 0 89.89 154.1 488 488
88.54 154.9 0 0 0 0 0 0
0 0 0 0 0.78 178.4 178.6 666.67
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 ];
NELEM=12;
NPOINT=51;
NPOINT;
NNODE=8;
VFCC=zeros(NPOINT*2,1) ;
NPOINT*2
VFCC
for IELEM=1:NELEM
for INODE=1:NNODE
NUMN=MCNT(IELEM,INODE)
2*NUMN-1
2*NUMN
VFCC(2*NUMN-1,1)=VFCC(2*NUMN-1,1)+CHARGE(2*IELEM-1,INODE);
VFCC(2*NUMN,1 )=VFCC(2*NUMN,1 )+CHARGE(2*IELEM ,INODE);
end
end
VFCC

Sign in to comment.

Answers (0)

Categories

Find more on Matrices and Arrays 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!