Creating vectors from columns of a matrix
5 次查看(过去 30 天)
显示 更早的评论
I have a matrix containing indices of elements for example:
A = [55 59; 242 270]
How can I create a matrix that has rows starting at the first element and ending at the second element of each row of A, i.e. :
B = [55 56 57 58 59; 242 243 ... 269 270]
0 个评论
采纳的回答
Dyuman Joshi
2023-5-13
You can not obtain the output you want in terms of numeric data type due to size mismatch for vertical concatenation. You can obtain the output in terms of cell arrays -
A = [55 59; 242 270]
out = arrayfun(@(x) A(x,1):A(x,2), 1:size(A,1), 'UniformOutput', false)'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!