HOW TO REPLACE SPECIFIC ELEMENTS IN A MATRICE?

Consider a 5x5 matrix A
How to replace the numbers on the locations (2:3,3) and (4,3:5) with zeros.
Help needed !!

 採用された回答

Jan
Jan 2022 年 4 月 23 日
編集済み: Jan 2022 年 4 月 23 日

0 投票

A = rand(5, 5);
A(2:3, 3) = 0;
A(4, 3:5) = 0;
Is this a homework question? If so: what a pity that you did not try it by your own. You see, that the translation from English to Matlab is not hard in this case.
Can you find an alternative using logical indexing, which inserts the zeros in one command?

2 件のコメント

Muhammad Safwan Khan
Muhammad Safwan Khan 2022 年 4 月 23 日
THANKS FOR HELPING
I'm Beginner & it is my first experience of practicing matlab.I didn't know much about it but hope gradually i will ace it..
Jan
Jan 2022 年 4 月 23 日
編集済み: Jan 2022 年 4 月 23 日
Do you know Matlab's onramp tutorial already? https://www.mathworks.com/learn/tutorials/matlab-onramp.html
The "Getting Started" chapters of the documentations are useful also.
With "logical indexing" (index using a logical mask):
A([0,0,0,0,0; ...
0,0,1,0,0; ...
0,0,1,0,0; ...
0,0,1,1,1; ...
0,0,0,0,0] == 1) = 0
With "linear indexing":
A([12, 13, 14, 19, 24]) = 0;
Here the elements are treated as A is a 1D vector.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2022 年 4 月 23 日

編集済み:

Jan
2022 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by