Display first and last rows and first and last columns at once?

조회 수: 3 (최근 30일)
Laura
Laura 2013년 10월 23일
댓글: Laura 2013년 10월 24일
I have a matrix of ones size 6X6. I want to take all of the 1's from the first and last rows and all of the 1's from the first and last columns and display them. It should look like the outline of a square.
Is this possible? The best I can get is either displaying all rows at once or all columns at once, not both.
Help would be very much appreciated.

채택된 답변

dpb
dpb 2013년 10월 23일
Only way to do this is by ascii representation--
>> x=ones(4);x(2:3,2:3)=0;
>> c=num2str(x);
>> c(c=='0')=' ';
>> disp(c)
1 1 1 1
1 1
1 1
1 1 1 1
>>
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2013년 10월 24일
n = 6;% n - size of your array (eg: n = [6 6])
x=ones(n);x(2:end-1,2:end-1)=0;
Laura
Laura 2013년 10월 24일
Brilliant, thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by