MATLAB: Extract numbers from mixed string. extractnumbersstring Str = ['<data seq="0"<temp8.0</temp<data seq="1"<temp6.9</temp']; I want to extract temp (8.0 & 6.9) I want to express in workspace ——————————- tem_1 = 8.0 tem_2 = 6.9 ——————————- Best Answer There are probably better ways to do this but if this is always going to be the string and only the numbers are going to change, you can use strfind() to get the locations of "temp"Something like this:xStr = strfind(Str, 'temp');temp_1 = str2double(Str(xStr(1)+4:xStr(1)+6));You should then be able to figure out temp_2.... Related SolutionsMATLAB: Extract 2 data(temperature) from string Use regexp to match strings whichfollow after the string "<temp"consist of (digit,period,digit)are followed by "</temp"str = [' <data seq="0" <temp8.0</temp <data seq="1" <temp6.9</temp '];cac = regexp( str, '(?<=<temp)\d\.\d(?=</temp)', 'match' );temp_2 = str2double(cac{2})temp_1 = str2double(cac{1})outputstemp_2 = 6.9000temp_1 = 8>>Or use sscanf. The format_string is a copy of Str, in which the "numbers" you want to extract are replaced by the specifier, %fnum = sscanf( Str, '<data seq="0" <temp%f</temp <data seq="1" <temp%f</temp' )which outputsnum = 8.0000 6.9000>> MATLAB: Please help me.. I want to import two data in string. http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval Related QuestionRandom integer numbers using random functionQuestion about fgetl(fileID)Strings to text file using num2str,strcat, and fprintfHow to read a specific number in a text file containing a mixture of strings and numbersVariable TempData must be of size [25 33]. It is currently of size [31 24]. Check where the variable is assigned a value.
Best Answer