how to make the same length in the struct
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luca Re
el 28 de Ag. de 2023
Comentada: Luca Re
el 30 de Ag. de 2023
i've a struct with filed of various length (see pics)
i want to make the same length of this array
and assign the zero in the data that is not there at the end
i try this ..but it's not correct
>> [Sis.d]
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
8 comentarios
Bruno Luong
el 29 de Ag. de 2023
Editada: Bruno Luong
el 29 de Ag. de 2023
This thread becomes completely a mess. The problem asked now has nothing to do with Padding arrays in structure.
The other thread should not be closed.
Respuesta aceptada
Bruno Luong
el 29 de Ag. de 2023
load('matlab_sis.mat')
Date = unique(cat(1,Sis.Date));
DAILYPROOF = nan(length(Date),length(Sis));
for k=1:length(Sis)
sk = Sis(k);
[tf, i] = ismember(sk.Date, Date);
DAILYPROOF(i,k) = sk.dailyprof;
end
T = table(Date, DAILYPROOF)
3 comentarios
Bruno Luong
el 29 de Ag. de 2023
Version without loop
n = length(Sis);
Date = {Sis.Date};
lgt = cellfun(@length, Date);
[Date, ~, i] = unique(cat(1,Date{:}));
j = repelem((1:n)',lgt(:));
DAILYPROOF = nan(length(Date),length(Sis));
DAILYPROOF(i+n*(j-1)) = cat(1,Sis.dailyprof);
T = table(Date, DAILYPROOF)
Más respuestas (1)
Bruno Luong
el 28 de Ag. de 2023
s=struct('a',rand(5,1),'b',rand(3,1),'c',rand(6,1))
maxheight = max(structfun(@height,s));
padarrays = structfun(@(x) [x; zeros(maxheight-height(x),1)], s, 'unif', 0)
padarrays.a
padarrays.b
padarrays.c
1 comentario
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!