how to extract a specific data from struct formatted dataset

13 visualizaciones (últimos 30 días)
i have battery dataset in a struct format. i need to extract "capacity" data alone from the dataset. the capacity data is present under 'discharge' only.
here is the dataset structure
i used the following code
z = load('B0005.mat');
for i = 1:length(z.B0005.cycle)
a(i) = z.B0005.cycle(i).data.Capacity;
end
the problem is, the first field('charge') does not contain 'capacity' data so it throws an error:
Reference to non-existent field 'Capacity'.
Error in Untitled (line 3)
a(i) = z.B0005.cycle(i).data.Capacity;
can anyone please tell me where iam going wrong and help me out in correcing the error. i want to read just the capacity data situated under discharge field

Respuesta aceptada

per isakson
per isakson el 23 de Abr. de 2020
Try this
%%
z = load('B0005.mat');
len = length(z.B0005.cycle);
a = zeros( len, 1 );
for ii = 1:len
if strcmp( z.B0005.cycle(ii).type, 'discharge' )
a(ii) = z.B0005.cycle(ii).data.Capacity;
end
end
Every second value of a will be zero

Más respuestas (1)

Muthu
Muthu el 23 de Abr. de 2020
Editada: Muthu el 23 de Abr. de 2020
I assume from the data and image that you have posted, the z.B0005.cycle(i) refers to 'charge' and 'discharge' which is placed consecutively: All 'discharge' in even and all 'charge' in odd indices.
Hence you can modify your code, so that you iterate only through your even indices.
for i = 1:length(z.B0005.cycle)
if mod(i,2)==0
a(i) = z.B0005.cycle(i).data.Capacity;
end
end
Hope this helps.
Good Luck.
  1 comentario
Padmamalini  T H
Padmamalini T H el 30 de Abr. de 2020
No the discharge data doesnt come in even indices. What i have shown is the initial recordings. After this there is no order and all charge and discharge recordings are random

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by