MATLAB: How to randomly change a digit in a string string I have a string = 00101 How i can randomly change one digits of that string? Ex: 00101=>00100 Best Answer string1 = '00101';digit_change = randi(length(string1));digit_val = str2num(string1(digit_change));digit_new = num2str(~digit_val);string1(digit_change)=digit_new; Related SolutionsMATLAB: How to search for substrings in a string You can specify that you want exactly 4 digits after '_K'my_strings = '1583_pwer_exp_Exxxx_aqxxx_tqx_K2_vxxx_K1001_'tmp = regexp(my_strings,'(?<=_K)\d{4}', 'match','once'); MATLAB: Cut character from string ss1 = ss(1:2);ss2 = ss(3:4);In matlab strings are vectors of type char. So you can use indexing. Related QuestionStrings of charactersHow to convert num2str for fprintf(fid, )
Best Answer