Getting values separated by commas from a string array
    조회 수: 38 (최근 30일)
  
       이전 댓글 표시
    
    Luis Ricardo Rivera Goitia
 2023년 3월 20일
  
    
    
    
    
    댓글: Luis Ricardo Rivera Goitia
 2023년 3월 21일
            I have this string array:
str 
113x 1
"52,884,410"
"44,878,410"
"46,896,410"
"82,941,410"
.
.
.
"130,890,415"
and I would like to extract each one of these values independently to assign a different variable to each one of them, for instance, X to the first group of numbers before the first comma, y to the group of numbers between commas, and z to the last group of numbers.
When using str2num or str2double it converts it to NaN insteas of numbers.
I used X = str2num(srt(1,:)) and I got the first one as a double [52 884 410], but don't know how to have only an array only for the first group to assign it to X taking into account all the values from the array.
댓글 수: 2
  Cris LaPierre
    
      
 2023년 3월 20일
				I think it would be easier to do somethign at the source. How is this variable created?
채택된 답변
  Cris LaPierre
    
      
 2023년 3월 20일
        str = ["52,884,410"
"44,878,410"
"46,896,410"
"82,941,410"
"130,890,415"]
tmp =  split(str,",");
x = str2double(tmp(:,1))
y = str2double(tmp(:,2))
z = str2double(tmp(:,3))
추가 답변 (1개)
  Steven Lord
    
      
 2023년 3월 20일
        You can do this with split and double.
S = ["52,884,410"
"44,878,410"
"46,896,410"
"82,941,410"]
S2 = split(S, ",")
D = double(S2)
This assumes each of the elements in S contains the same number of numbers. If not split will throw an error.
T = ["123,456"; "789,012,345"]
T2 = split(T, ",")
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


