Changing elements with a condition

4 次查看(过去 30 天)
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?

请先登录,再进行评论。

采纳的回答

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