Filter löschen
Filter löschen

Reading data into a structure

11 Ansichten (letzte 30 Tage)
Edward am 26 Sep. 2013
Beantwortet: Walter Roberson am 26 Sep. 2013
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
fid = fopen('/path/to/your/file.txt', 'rt');
output = textscan(fid, '%s %s %f %f %f', 'Delimiter', ' ,');
now i want to read this into an array of structures s. I have tried using the following: = output{1};
s.time = output{2};
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Sep. 2013
[s{1>length(output{1})}.date] = [output{1}{:}];
[s{:}.time] = [output{2}{:}];

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 26 Sep. 2013
Bearbeitet: Azzi Abdelmalek am 26 Sep. 2013
%That's what you have
s =
date: [1 2 3 4 5 6 7 8 9 10]
%and you want
s =
1x10 struct array with fields:


Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by