HOW CAN I RE-EDIT MATRIX?
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
José-Luis
2014-5-22
your_mat = cell2mat(arrayfun(@(n) repmat(a(n,[1 3]),a(n,2),1),(1:size(a,1))','uniformoutput',false));
更多回答(1 个)
Geoff Hayes
2014-5-22
First determine the dimensions of the new matrix (called B say) which will mx2 where m is the sum of the middle column. Then iterate over each row of your initial matrix (called A say) and replicate the end points of that row (first and third columns) by the value in the second column:
B(j:j+A(i,2)-1,:) = repmat([A(i,1) A(i,3)],A(i,2),1);
where i is the ith row of A and j is the next row to insert your replicated block (with j being incremented on each iteration). So in the above piece of code, we are replacing all rows in B from j to j+A(i,2)-1 with the ends of the ith row of A replicated A(i,2)x1 times.
Hope that the above helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!