Create vector of cell arrays of ranges from 0 to the value in each index of another vector

21 次查看(过去 30 天)
I need help writing code that does the following:
Iterate through a vector; for each index, create a cell array that ranges from 0 to that value at that index, in increments of 1. This should create a vector of cell arrays, with each cell being a vector containing the range for each cell of the original vector.
For instance, if the first cell in the original vector is a 6, then the first cell of the cell array should be [0 1 2 3 4 5 6]. Then if the next cell in the original vector is 9, the second cell in the cell array should be [0 1 2 3 4 5 6 7 8 9]. And so on.
Here is my attempt to do this:
max_fr = max(firing_rates); % creates a 1x143 vector of single values
m = [];
m_vector = {};
for i = 1:143
m = max_fr;
m_vector(1:i) = {0:1:m};
end
But this only creates a 1x143 vector of cell arrays that are all the same as the first cell, though it correctly creates [0 1 2 3 4 5 6] for that cell.

采纳的回答

Akira Agata
Akira Agata 2020-3-15
Like this?
% Example of original cell
oriCell = {6;9;3;8;2};
% Generated cell array
outCell = cellfun(@(x) 0:x,oriCell,'UniformOutput',false);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by