taking multiple column to form a struct
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hello, I have a data set from text file, which is a 1x 13 size file. first I diff the data only to take the value of the data from clumn 13 (the counter) when it increases (some have repeated same numbers).
DataCube = textscan(D, '%f %f %f %f %f %f %f %f %f %f %f %f %f', 'HeaderLines', 13);
f = [true;diff(DataCube{1,13})~=0];
then when I try to extract the rest of the data into a struct such that:
Kid(1).Force{1,1:6} = DataCube{:, 1:6}(f==1);
the result returns: Expected one output from a curly brace or dot indexing expression, but there were 6 results. apart from extracting them individually, how else can I extract them in one go?
0 comentarios
Respuestas (1)
Guillaume
el 21 de Dic. de 2015
First, f==1 is a no-op, it's exactly the same as f.
Note that DataCube{:, 1:6} returns 6*number or rows individual values, so you would need as many output variables. It's probably not what you wanted to do. Possibly, this is what you wanted to do:
Kid.Force = DataCube(f, 1:6);
This will store the cell array only for those rows where f is true into a single field of your structure.
I looks like you're a bit confused by cell array syntax. My advice is to drop the cell array by converting it straight away to matrix, since it only holds scalar numerics:
DataCube = cell2mat(textscan(D, '%f %f %f %f %f %f %f %f %f %f %f %f %f', 'HeaderLines', 13));
f = [true;diff(DataCube(:,13))~=0]; %did you make a typo and replace : with 1?
2 comentarios
Guillaume
el 21 de Dic. de 2015
f is already logical (0s and 1s), so comparing it to 1 returns the exact same values: 0==1 -> 0, 1==1 -> 1
I do not understand what you're trying to do with your Force{trial, 1:6}. It looks like you are trying to distribute your 6 columns of the cell array to 6 columns of the Force field, but at the same time, f is likely to select several rows which you are trying to put into a single row (trial).
What in your DataCube cell array corresponds to a given force or trial?
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!