Vecotrizing a for loop
5 次查看(过去 30 天)
显示 更早的评论
I have been trying to write more efficient piece of code and one obvious aspect of doing that is vectorization.I know the basic stuff about that but here's where I can't figure out. So, I have a cell array "dataCell" in which each cell contains a single vector. The length of the vector varies across the cells. Now, I wish to put all the vectors in a single vector named "dataRow" and to make use of vectorisation, I have two another vectors "startIndex" and "numberOfElements" that give the first and the last index for each vector in dataCell that it should occupy in the vector "dataRow". Here is the for loop version of what I wish to do,
for i=1:length(dataCell)
dataRow(startIndex(i)+1:startIndex(i)+numberOfElements(i))=dataCell{i}
end
Can anyone suggest anything? Thanks!
2 个评论
采纳的回答
更多回答(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!