필터 지우기
필터 지우기

Reading data into a structure

조회 수: 5 (최근 30일)
Edward
Edward 2013년 9월 26일
답변: Walter Roberson 2013년 9월 26일
Hi, im reading the file:
26/09/2013,16:04:40 2412 928.0 49.94930
25/09/2013,14:24:30 2412 914.0 -999999
using:
fid = fopen('/path/to/your/file.txt', 'rt');
output = textscan(fid, '%s %s %f %f %f', 'Delimiter', ' ,');
fclose(fid);
now i want to read this into an array of structures s. I have tried using the following:
s.date = output{1};
s.time = output{2};
etc
however this gives me size(s) = 1 (a single structure with arrays of dates and times as members) I would prefer to have an array of structures each with a single date and time. Is this possible?

채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 26일
[s{1>length(output{1})}.date] = [output{1}{:}];
[s{:}.time] = [output{2}{:}];

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 26일
편집: Azzi Abdelmalek 2013년 9월 26일
%That's what you have
y=1:10
s.date=y
%result
s =
date: [1 2 3 4 5 6 7 8 9 10]
%and you want
s=struct('date',num2cell(y))
%result
s =
1x10 struct array with fields:
date

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by