Changing the boundary rows and columns.

I'm having a bit of a problem finding a solution to this most likely due to the answer being relatively simple. I have a matrix of all ones. Let's say,
[1,1,1,1; 1,1,1,1; 1,1,1,1] What I need to do is relatively simple. I need to change the values of the first and last columns and rows to zero such that the matrix would be.
[0,0,0,0; 0,1,1,0; 0,0,0,0]
Is there a way to tell matlab to give a value of zero to every number within a given column or row?

 채택된 답변

Matt Fig
Matt Fig 2011년 4월 27일

0 개 추천

A = [1,1,1,1; 1,1,1,1; 1,1,1,1];
A([1,end],:) = 0; % Changes the first and last row.
A(:,[1,end]) = 0; % Changes the first and last column.

댓글 수: 1

Jonathon
Jonathon 2011년 4월 27일
Thanks. I figured such an operation would be relatively simple unfortunately being too simple means few ever think to comment on it.

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

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 4월 27일

0 개 추천

m=[1,1,1,1; 1,1,1,1; 1,1,1,1];
m(:,1)=0; %all lines, first column
m(1,:)=0; %all columns, first line
m(:,size(m,2))=0; %all lines, last column
m(size(m,1),:)=0; %all columns, last line

카테고리

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

질문:

2011년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by