Quantcast
Channel: MATLAB Central Newsreader - tag:"table"
Viewing all articles
Browse latest Browse all 48

Re: How avoid a loop for in a table?

$
0
0
On 12/22/2016 3:06 AM, Adriano wrote:
> Hi everyone,
>
> I have a very big table called "export" (more than 2000000 rows) with a
> column of dates called "expiration" and I have this part of 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
>
> My problem is that the loop for is very slow. Anyone knows how to avoid
> the loop for to get the same result? thanks a lot!!

ix=(weekday(export.Expiration(i,1))==7);
export.Expiration(i,1)=cellstr(datetime(datenum(export.Expiration(ix,1))-1,...
                        'ConvertFrom','datenum','Format','MM/dd/yyyy'));

But why convert the actual variable to string at all, why not just
display as desired from the base value if use the datetime class
instead? And, even more why are you mixing the two???

Viewing all articles
Browse latest Browse all 48