matlab get the value of char

后端 未结 3 1976
面向向阳花
面向向阳花 2021-01-29 14:56

from MATLAB command line , when I type my variable a , it gives me values as expected :

a =


            value_1
            value_2

and I wou

3条回答
  •  野的像风
    2021-01-29 15:32

    Perhaps a is a string with a newline in it. To make two separate variables, try:

    values = strtrim(strread(a, '%s', 'delimiter', sprintf('\n')))
    

    strread will split a into separate lines, and strtrim will remove leading/trailing whitespace. Then you can access the lines using

    values{1}
    values{2}
    

    (note that you must use curly brackets since this is a cell array of strings).

提交回复
热议问题