How Can I avoid a loop for in a table?
古いコメントを表示
Hi everyone,
I have a table called 'export' with more than 2000000 rows. One of its column, called ' Expiration', is a dates vector. I woul like to avoid the loop for in this code:
for i = 1:size(export,1)
if weekday(export.Expiration(i,1))==7
export.Expiration(i,1) = cellstr(datetime(datenum(export.Expiration(i,1))-1,'ConvertFrom','datenum','Format','MM/dd/yyyy'));
end
end
Can somebody help me? Many thanks.
3 件のコメント
John BG
2016 年 12 月 22 日
can you make available a few lines of your table so readers can work on the sample directly?
Shadi Mahdiani
2016 年 12 月 22 日
If you can provide a few rows of your table, it would be easier to find out what you are exactly looking for. But generally find and strncmp help when you struggle with big tables and want to avoid for loops.
Guillaume
2016 年 12 月 22 日
Indeed an example would have made things clearer, however the format can be inferred from the given code. export.Expiration is a column of date strings in the form 'MM/dd/yyyy'
The purpose of the loop is to change the date to the day before when it is the last day of the week.
採用された回答
その他の回答 (1 件)
KSSV
2016 年 12 月 22 日
0 投票
You can convert your table into cell using table2cell and access complete row/column you want.
2 件のコメント
Guillaume
2016 年 12 月 22 日
You can access complete rows/columns of a table directly with indexing or dot notation, there's no need to waste time converting them to anything.
KSSV
2016 年 12 月 23 日
That's true....but if any head lines of the table present, they do come along with row/ column. Isn't it?
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!