필터 지우기
필터 지우기

How to make this complicated array

조회 수: 1 (최근 30일)
Brandon M
Brandon M 2016년 10월 7일
편집: Thorsten 2016년 10월 7일
I have attached the picture below. Anyone can tell me how to make that array? I want the middle part if possible just all zeros. If possible, I would like to use the x and y to make that array
  댓글 수: 2
Jan
Jan 2016년 10월 7일
This sounds like a homework question. So please post, what you have tried so far and ask a specific question.
Andrei Bobrov
Andrei Bobrov 2016년 10월 7일
Hi Jan!
Most likely this is the Cody.

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

답변 (3개)

dbmn
dbmn 2016년 10월 7일
x=5;
y=8;
a=(1:2*x+2*y-2);
A=zeros(5,8);
A(:,1) = a(:, 1:x)';
A(end,2:end) = a(:, x+1:x+y-1);
A(end-1:-1:2,end) = a(:, x+y:2*x+y-3)';
A(1,end:-1:2) = a(:, 2*x+y-2:end-2);

Andrei Bobrov
Andrei Bobrov 2016년 10월 7일
편집: Andrei Bobrov 2016년 10월 7일
x=5;
y=8;
n = 1:(x+y-2);
a = zeros(x,y);
a([1:x,2*x:x:x*y-x]) = n;
out = a + rot90((a + n(end)).*(a > 0),2);

Thorsten
Thorsten 2016년 10월 7일
편집: Thorsten 2016년 10월 7일
x = 5; y = 8;
a(x,y) = 0;
a([1:x 2*x:x:y*x y*x-1:-1:x*(y-1)+1 x*(y-2)+1:-x:x+1]) = 1:2*x+2*(y-2);

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by