필터 지우기
필터 지우기

change even column values only

조회 수: 3 (최근 30일)
PK
PK 2016년 9월 29일
댓글: Thorsten 2016년 9월 29일
I create 20*20 2D array of all ones. And then I want to change even columns to minus one. How can I change with builtin function?

채택된 답변

Thorsten
Thorsten 2016년 9월 29일
A = ones(20);
A(:,mod(1:20, 2) == 0) = -1;
  댓글 수: 2
PK
PK 2016년 9월 29일
good answer! I got the following method.... A = ones(20) A(:,2:2:end) = -1
Thorsten
Thorsten 2016년 9월 29일
You method is even better!

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

추가 답변 (1개)

PK
PK 2016년 9월 29일
good answer! I got the following method.... A = ones(20) A(:,2:2:end) = -1

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by