Simple for loop efficiency
显示 更早的评论
Hello, this is my first post here. Currently I am working on a script that should recalculate the column numbers as following:
firstvalue = table{1,1};
i = 1;
height = height(table);
for i = 1:height
x = table{i,1};
table{i,1} = (x-firstvalue)/fs*1000;
i = i+1;
end
This loop does what I want, but is terribly slow. Is there a way to make this loop execute faster? The loop works in the table with around 50.000 rows. I think the loop could be more efficient but don't know how.
Thank you!
3 个评论
What is 'table'? Is it a Table object? I'm not familiar with tables, but if it is a table then I would imagine it is quicker to calculate all your results into a numeric array first (extract all the first column of the table at once) and then assign the whole thing to the table in one go rather than updating each row of the table directly. Not sure if this is possible with tables though since I don't use them. It is a usual Matlab strategy for objects such as uitable though.
Jan
2017-1-18
Omit the "i=i+1". It is only confusing inside a loop. A corresponding warning should appear in the editor.
Daniel van Dijk
2017-1-18
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Fixed-Point Designer 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!