Replace cell elements with a constant value?

5 views (last 30 days)
RB
RB on 30 Aug 2018
Commented: Image Analyst on 4 Sep 2018
Right now, I have a 4x4 cell and in each element of the cell is 25x25 values. I want to be able to go into the first cell element (1,1) and replace every single one of the 25x25 values with a constant (already defined as a variable earlier in my code). This will be within a for loop, and k has been defined as the cell element number (1 through 16 since the cell is 4x4). I am hoping to just be able to say within cell{k} replace every element with constant. And then I want to proceed and be able to replace every single cell element. Therefore, the end will be a 4x4 cell. Within each cell element, there will be 25x25 values that are all the same. Thank you for any help!

Answers (1)

Image Analyst
Image Analyst on 30 Aug 2018
Try this (untested)
for k = 1 : numel(ca) % For every cell
% Make array of all one number.
% Then replace existing contents with this array.
ca{k}= yourConstant * ones(size(ca{k}));
end
It uses linear indexing so it should still retain the 2-D shape of the cell array, ca.
  2 Comments
RB
RB on 4 Sep 2018
I tried this code, and I get the error message: GLCM does not count pixel pairs if either of their values is NaN. And instead of replacing each 25x25 array in the 4x4 cell with the corresponding value, it is replacing every value in the cell with NaN. Do you have any idea what might be going wrong? Thanks!
Image Analyst
Image Analyst on 4 Sep 2018
Attach your full code. I don't even use anything called GLCM or call graycomatrix() or graycoprops(), so it's your code, not mine that's giving the error. You did not even mention that you were using the Gray Level Cooccurrence Matrix before now.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!