# How to replace the 5 in my vector with decreasing numbers like 5,4,3,2,1

2 views (last 30 days)
Pallav Patel on 23 Feb 2020
Answered: Walter Roberson on 24 Feb 2020
x(3:4,3:5) = 5

Image Analyst on 24 Feb 2020
The 5 what?
1. The 5 values in the matrix that equal 5?
2. Five elements in your matrix?
It's ambiguous because it's not clearly worded. How can you replace one number -- "the 5" -- with a set of 5 numbers? Are there exactly 5 elements in your matrix that have the value 5? What is the order that you replace them with: column major, or row major?
You are specifying a submatrix of 6 indexes. You didn't tell us how big x is or what its values are. Is this homework?
Walter Roberson on 24 Feb 2020
This is not clear, as you do not appear to have a vector.
Pallav Patel on 24 Feb 2020
Try the command in Matlab and you will see the columns and rows specified will be filled with 5's. Matlab automatically fills an undefined vector with zeros. what I am trying to do is have a decreasing or increasing number and that was just a template to upload to Mathworks. I have seen such an example before but can't seem to find it.

Walter Roberson on 24 Feb 2020
x(3:4,3:5) = reshape(5:-1:0, 2, 3);

madhan ravi on 23 Feb 2020
Z=num2cell(x);
Z(cellfun(@(zx)zx==5,Z))={5:-1:1}
celldisp(Z)

#### 1 Comment

Pallav Patel on 24 Feb 2020
Thank you Madhan. Is ther any way I can do it without the cell function.