I am trying to convert data file (here string representing file with three lines) into a structure array like this:
cel = textscan('1 1.1 2 2.2 3 3.3', '%u %f');
str = cell2struct(cel, {'f1', 'f2'}, 2);
However, now I have a struct array of dimension 1x1, where I can only access the columns using array's fields, but not the whole rows (like 'str(2)' for the second row).
What I need is to have an array of structs (or how it can be called) like this:
str = struct('f1', {1, 2, 3}, 'f2', {1.1, 2.2, 3.3});
because now I can (for instance) filter it like this:
subStr = str(find([str.f1] > 1))
which I could not do in the first case. Any idea how to get there? At the end I was able to do it by:
cel = textscan('1 1.1 2 2.2 3 3.3', '%u %f');
[f1, f2] = cel{:};
str = struct('f1', num2cell(f1'), 'f2', num2cell(f2'));
But it does not feel right and I am afraid it will be expensive (the files are quite large).
EDIT:
My solution is indeed too memory demanding, therefore not usable. Typical files have header, footer, and c. 5e6 lines of data in six columns.
Thanks
tablefor this? It seems likestructs would needlessly complicate your life...table. I knowstructfromnumpywhere I find them quite usefull. However as I pointed in comment to your answer, they seem to be memory demanding (and probably overkill for my usecase).