Create vector of cell arrays of ranges from 0 to the value in each index of another vector
3 ビュー (過去 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
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 Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!