Help in creating Matrix

I want to create a function called LMatrix that generates the following output given three inputs,A,B,and i,where A is an n x n matrix,B is an n x m matrix,and i is a positive integer.
*Output *
Code
function L= LMatrix (A,B.i)
[ar ac] = size(A);
[br bc] = size(B);
[lr lc] = size(L);
if nargin < 4
r = 1; c = 1;
else
r = round(r); c = round(c);
end
L = [A,B];
rr = r + br - 1;
cc = c + bc - 1;
out(r:rr,c:cc) = L;
Test Cases
>> A = 2; B = 1; i = 3;
>> L1 = LMatrix(A,B,i)
L1 =
100 210 421
>> A = [1 4; 2 3]; B = [2; 1]; i = 3;
>> L2 = LMatrix(A,B,i)
L2 =
200 100 620 710
34 6 2 33 7 1

댓글 수: 1

Teddy Xiong
Teddy Xiong 2012년 10월 19일
are you sure you have the right output in your function declaration?

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

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 19일
편집: Azzi Abdelmalek 2012년 10월 19일

0 개 추천

A=magic(2);B=[1; 2];
n=5
p=cell2mat(arrayfun(@(x) [zeros(x,1) ;(1:n-x)'] ,(1:n)','un',0)')
C=cell2mat(arrayfun(@(x) [zeros(x-1,1) ;ones(n-x+1,1)] ,(1:n)','un',0)')
out=cell2mat(cellfun(@(x,y) A^x*B*y,num2cell(p),num2cell(C),'un',0))

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by