Indexing through a cell array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hari krishnan
el 23 de Sept. de 2021
Comentada: Jan
el 23 de Sept. de 2021
I am looking to populate cell array named 'age_list' based on the values i have in two columns; named 'day' and 'pop'
- For each specific 'day', i am looking at the corresponding 'pop' value and then update the 'age_list' based on it.
- Example: On day 4, the population is 3. Therefore the cell array 'age_list' will have 'three' values with the {2,3,4}.
Can anyone suggest me on how to perform this? Any help will be appreciated.
6 comentarios
Respuesta aceptada
Jan
el 23 de Sept. de 2021
A bold try:
day = 1:7;
pop = [1,2,3,3,3,4,6];
age_list = cell(1, numel(day));
age_list{1} = 1; % Is this given?!
for k = 2:numel(day)
new = pop(k) - pop(k - 1);
age_list{k} = cat(2, repmat(age_list{1}, 1, new), age_list{k-1} + 1);
end
age_list
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays 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!