Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Laura
Laura am 23 Okt. 2013
Kommentiert: Laura am 24 Okt. 2013
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.

Akzeptierte Antwort

dpb
dpb am 23 Okt. 2013
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 Kommentare
Andrei Bobrov
Andrei Bobrov am 24 Okt. 2013
n = 6;% n - size of your array (eg: n = [6 6])
x=ones(n);x(2:end-1,2:end-1)=0;
Laura
Laura am 24 Okt. 2013
Brilliant, thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by