MATLAB: How to make upper (1) and lower (0) words of a text using 0’s and 1’s

lowercaseMATLABuppercase

Hi.
I'm stuck in a problem where I need to read a file and make the words of the file uppercase if I have a 1 or lowercase if I have a 0.
I have a binary 'code', and I need to change the words of another text transforming every 1 and 0 of the binary code into uppercase (if it's a 1) or lowercase (if it's a 0) word.
Thanks.

Best Answer

Here's a demo that converts a single string into upper and lower case defined by a logical vector. The vector has one element for each word. If you have any trouble adapting this to your needs please provide more detail about the data you're working with.
str = 'That''s one small step for a man, one giant leap for mankind.';
ul = logical([1 0 0 0 0 0 0 1 1 1 1 1]);
% parse sentence into words
strWords = strsplit(str); %see optional 2nd input
% Set upper & lower case words
strWords(ul) = upper(strWords(ul));
strWords(~ul) = lower(strWords(~ul));
% Concatenate words back into sentence
strFinal = strjoin(strWords)
%Result:
% 'THAT'S one small step for a man, ONE GIANT LEAP FOR MANKIND.'