Replacing a whole row of a matrix with specific characters

3 views (last 30 days)
Hi all,
I have a big matrix, 432000 * 5 (char type). the elements of the matrix are binary (0s and 1s). I want to replace each row with a specific character (e.g. if row is '1 0 1 1 1', it should be replaced by "X"), whereever it appears in the whole matrix.
I am trying the following code but it is giving only 1*32 cell output (1 row, 32 columns and only last column is replaced/updated).
actual matrix (the 432000*5 one) is dependent on my input, which is an image, and it can vary.
I am expecting 432000 characters (either in rows or columns), i.e. each row of original matrix is replaced with corresponding allocated character.
for j=1:len; %len is 432000 in this case, it could vary depending on my input
result = strrep(R(j,:),{'00000','00001','00010','00011','00100','00101','00110','00111','01000','01001','01010','01011','01100','01101','01110','01111','10000','10001','10010','10011','10100','10101','10110','10111','11000','11001','11010','11011','11100','11101','11110','11111'},{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5'});
end

Answers (1)

Mohammad Sami
Mohammad Sami on 14 Apr 2020
a = char(randi([0 1],4000,5)+'0'); % create a n by 5 char array
b = bin2dec(a); % convert it to decimal
b(b>25) = b(b>25) - 'A' + '0' - 26; % correct for poisition of numbers
c = char(b + 'A'); % convert back to char
  1 Comment
UET Hussain
UET Hussain on 14 Apr 2020
could not get the point.
the point is, i wanted to replace each row by a new character. whereever a specific pattern (5 bits) appears, it should be replaced by corresponding character. e.g. if 0 0 0 0 0 appears, it should be replaced by A etc.

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!