텍스트 파일에서 한 줄을 읽으려고합니다. 이 줄은 textscan
을 사용하여 단어로 나뉩니다. textscan
의 출력은 구조체 배열 내에 저장됩니다. 각 구조는 한 단어와 위치를 텍스트 파일에 저장합니다.셀 배열의 데이터를 구조체 배열로 복사
Result Time Margin Temperature
를 그리고 구조의 배열을 원하는 경우 :
예를 들어, 텍스트 파일은 다음과 같이 보일 수 등
headerRow(1).header = Result
headerRow(1).location = 1
headerRow(2).header = Time
headerRow(2).location = 2
하고 있습니다. 이것은 내 코드입니다 :
headerRow = struct('header', 'location');
headerLine = fgets(currentFile)
temp_cellArray = textscan(headerLine, '%s', ' ')
for i = 1:size(temp_cellArray),
headerRow(i).header = temp_cellArray{i,1}
headerRow(i).location = i
end
그러나 이것은 전체 4x1 셀만 배열의 첫 번째 요소에 저장합니다. 코드를 원하는대로 작동하게하려면 어떻게해야합니까?