HOW TO ACCESS THE FOLLOWING ELEMENTS FROM THE GIVEN ARRAY

a=
0 0 0.3013 1.1305
1.0000 2.0000 0.7390 0.4223
3.0000 2.0000 1.1305 -0.2111
I need
A1=[[a(1,1) a(2,1) a(1,3) a(2,3)]' [a(1,2) a(2,2) a(1,4) a(2,4)]' ] A2=[[a(2,1) a(3,1) a(2,3) a(3,3)]' [a(2,2) a(3,2) a(2,4) a(3,4)]' ]

2 件のコメント

Cedric
Cedric 2014 年 5 月 21 日
What doesn't work with the current approach? Do you need to generalize it to larger arrays? If so, what will be the size of these arrays and what will you want to perform ultimately?
BIRAJA
BIRAJA 2014 年 5 月 25 日
編集済み: BIRAJA 2014 年 5 月 25 日
Sir,
I want to access the elements of the given matrix as per the sequence. It can be increased to 50-rows and 50-columns. I want a generalized code.

サインインしてコメントする。

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2014 年 5 月 25 日

1 投票

A1 = reshape(permute(reshape(a(1:end-1,:),2,2,[]),[1,3,2]),[],2);
a02 = [a(:,2:end-1);a(2:end,end)'];
A2 = reshape(permute(reshape(a02',2,2,[]),[1 3 2]),[],2);
George Papazafeiropoulos
George Papazafeiropoulos 2014 年 5 月 25 日

0 投票

a=[ 0 0 0.3013 1.1305;
1.0000 2.0000 0.7390 0.4223;
3.0000 2.0000 1.1305 -0.2111];
A1=[[a(1,1) a(2,1) a(1,3) a(2,3)]' [a(1,2) a(2,2) a(1,4) a(2,4)]' ]
A2=[[a(2,1) a(3,1) a(2,3) a(3,3)]' [a(2,2) a(3,2) a(2,4) a(3,4)]' ]
for i=1:size(a,1)-1
b=a(i:i+1,:);
b=b(:);
n1=1:size(a,2)-1;
b1=b;
ind1=3+cumsum([0,2+(-1).^n1]);
b1(ind1)=[];
b2=b;
ind2=1+cumsum([0,2+(-1).^n1]);
b2(ind2)=[];
A=[b1 b2]
end

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2014 年 5 月 21 日

回答済み:

2014 年 5 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by