Find zeros in a part of a matrix

1 view (last 30 days)
Hi all,
I have a matrix such that:
Tarr =
1.0e+05 *
0.0006 0.0000 0.0000 0.0000 0
0.0002 0 0 0 0
0.0001 0 0 0 0.0001
0.0004 0 0 0 0
0 1.3018 1.4506 0.2323 0.0540
0.0005 0.0000 0.0000 0 0
0.0002 0 0 0 0
0.0000 0 0 0 0
0.0004 0 0 0 0
0 -2.9018 -3.0506 0.2323 0.0540
0.0005 0 0 0 0
0.0002 0 0 0 0
0.0000 0 0 0 0
0.0004 0 0 0 0
0 0 0 0.2323 0.0540
I would like to find the indices of the zero elements in the following subsection of the matrix
Tarr(5:5:end,2:end)
An then replace those with some numbers I desire. I know this must be fairly easy, however I cant seem to be able to find a straightforward way.
KR,
KMT.

Accepted Answer

Jos (10584)
Jos (10584) on 28 Nov 2017
temp = Tarr(5:5:end,2:end) ; % get the relevant portion
temp(temp==0) == 12345 ; % your value
Tarr(5:5:end,2:end) = temp ; % put the edited portion back in

More Answers (0)

Community Treasure Hunt

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

Start Hunting!