Changing elements with a condition

조회 수: 4 (최근 30일)
Onur Güven
Onur Güven 2018년 12월 21일
댓글: Onur Güven 2018년 12월 21일
Hi all,
I've some basic questions about changing the elements of a 9x9 matrix with a specific condition. The matrix is;
X1 =
0 0 0 0 0 0 0 0 0
0.2778 0.2800 0 0 0 0 0 0 0
0.2222 0.2000 0.3700 0 0 0 0 0 0
0.1333 0.1600 0.1750 0.4600 0 0 0 0 0
0.0889 0.0960 0.1400 0.1500 0.5950 0 0 0 0
0.0667 0.0640 0.0840 0.1200 0.1125 0.5950 0 0 0
0.0611 0.0480 0.0560 0.0720 0.0900 0.1125 0.6400 0 0
0.0444 0.0440 0.0420 0.0480 0.0540 0.0900 0.1000 0.6400 0
0.0222 0.0320 0.0385 0.0360 0.0360 0.0540 0.0800 0.1000 0.6400
And I want to create X2 as
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0.278 0.280 0 0 0 0 0 0
0 0.222 0.200 0.370 0 0 0 0 0
0 0.133 0.160 0.175 0.460 0 0 0 0
0 0.089 0.096 0.140 0.150 0.595 0 0 0
0 0.067 0.064 0.084 0.120 0.113 0.595 0 0
0 0.061 0.048 0.056 0.072 0.090 0.113 0.640 0
0 0.044 0.044 0.042 0.048 0.054 0.090 0.100 0.640
And X3 as
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0.278 0.280 0 0 0 0 0
0 0 0.222 0.200 0.370 0 0 0 0
0 0 0.133 0.160 0.175 0.460 0 0 0
0 0 0.089 0.096 0.140 0.150 0.595 0 0
0 0 0.067 0.064 0.084 0.120 0.113 0.595 0
0 0 0.061 0.048 0.056 0.072 0.090 0.113 0.640
Thanks to everyone for solution.
;
  댓글 수: 2
Rik
Rik 2018년 12월 21일
You mean you want to make a copy and assign zeros to specific rows and columns?
Onur Güven
Onur Güven 2018년 12월 21일
yes.

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

채택된 답변

James Tursa
James Tursa 2018년 12월 21일
clear X2 X3
[m,n] = size(X1);
X2(2:m,2:n) = X1(1:m-1,1:n-1);
X3(3:m,3:n) = X1(1:m-2,1:n-2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by