필터 지우기
필터 지우기

How to edit matrice to another matrice?

조회 수: 1 (최근 30일)
Yamina chbak
Yamina chbak 2020년 3월 23일
댓글: Sriram Tadavarty 2020년 3월 23일
% how to edit matrice A to matrice B with
% A=[1 a b c
% 2 d e f
% 3 g h i];
% %
% B=[ 1 a b 0
% 2 b c 0
% 3 c a 0
% 4 d e 0
% 5 e f 0
% 6 f d 0
% ...
% 9 i g 0 ]
%% I have a code for this but it's not work
A=[1 a b c; 2 d e f; 3 g h i];
[m,n]=size(A);
B=zeros(3*m,n);
for i=1:3*m
B(i,1)=i;
B(i,4)=0;
end
for k=1:3
for i=1:3:3*m
B(i,2)=A(k,2);
B(i,3)=A(k,3);
end
for i=2:3:3*m
B(i,2)=A(k,3);
B(i,3)=A(k,4);
end
for i=3:3:3*m
B(i,2)=A(k,4);
B(i,3)=A(k,2);
end
end
B
  댓글 수: 1
Yamina chbak
Yamina chbak 2020년 3월 23일
You can choose a number for a,b,c,d,e,f, and g

댓글을 달려면 로그인하십시오.

채택된 답변

Sriram Tadavarty
Sriram Tadavarty 2020년 3월 23일
Hi Ahdia,
To perform just what you have asked for, you can do something as below:
a = 10;
b = 20;
c = 30;
d = 40;
e = 50;
f = 60;
g = 70;
h = 80;
i = 80;
A=[1 a b c; 2 d e f; 3 g h i];
Atemp = A(:,2:end); % Extacting the different variables
ACTemp = circshift(Atemp,-1,2); % Performing the circular shift
CTemp = [Atemp ACTemp]; % Combine both matrices and extract the respective indices
BTemp = reshape([CTemp(:,1:3:end) CTemp(:,2:3:end) CTemp(:,3:3:end)]',[],1);
B = zeros(9,4);
B(:,1) = 1;
B(:,2) = BTemp(1:2:end);
B(:,3) = BTemp(2:2:end);
Hope this helps.
Regards,
Sriram
  댓글 수: 2
Yamina chbak
Yamina chbak 2020년 3월 23일
Yeeeeeeeeees, It's work . Thinks you for help me Siriram. I do hope you will be as happy as I am now !
Sriram Tadavarty
Sriram Tadavarty 2020년 3월 23일
Glad that it helped. Feel free to accept the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by