tall array assignment with tall logical vector

The Matlab documentation 'Index and View Tall Array Elements' states the following:
"( )" Assignment
You can assign elements into a tall array using the general syntax A(m,n,...) = B. The tall array A must exist. The subscripts m,n,... cannot exceed the dimensions of A, and the first subscript m must be either a colon : or a tall logical vector. With this syntax, B can be:
  • Scalar
  • A tall array with the appropriate size
  • An empty matrix, []
However, I get the following error message "In the assignment A(m,n,...)=B, B must be a scalar value.", when I execute my code. I am simply trying to proces some files consisting of 5 columns. The last column contains strings of the format '2016-12-31 00:01:00 UTC'. I want to convert this last column into the datetime data type. For this I think I first need to remove the trailing ' UTC', as including literal characters at the end of a datetime InputFormat does not seem to work (unlike, e.g., '2016-12-31T00:01:00' that can be formatted as 'uuuu-MM-dd''T''HH:mm:SS'). With the following code I try to remove the ' UTC' wherever it is present in my last column. The code fails at the last statement (and I have checked the sizes).
ds = datastore(some_path,'ReadVariableNames',true,'NumHeaderlines',0,'Delimiter',delimiter,'TextscanFormats',{'%s','%s','%s','%f','%s'},'TextType','string','ReadSize','file');
rdata = tall(ds);
TF = endsWith(rdata.UtcTime(:),' UTC');
lC = rdata.UtcTime;
B = replace(lC(TF,1),' UTC','');
lC(TF) = B;
Am I misinterpreting the documentation or what could be the reason for this error?

댓글 수: 1

Thanks for reporting this. Yes, this is a mismatch between the documentation and the implementation. This form of assignment is not supported. ( help tall/subsasgn has a correct list of what forms are supported).

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2017년 1월 10일

2 개 추천

The documentation does not match the actual implementation by MathWorks. The error is generated at line 32 of fullfile(matlabroot, '\toolbox\matlab\bigdata\+matlab\+bigdata\+internal\+adaptors\GeneralArrayParenIndexingMixin.m') after the simple test if istall(b) (b being the assignor). So it is generated as soon as you try to assign a tall array regardless of whether or not its size matches that of the destination.
This is worthy of a bug report to Mathworks.
With regards to datetime, the input format can include a timezone, but you also have to specify which timezone you want the datetime in:
datetime('2016-12-31 00:01:00 UTC', 'InputFormat', 'yyyy-MM-dd HH:MM:ss z', 'TimeZone', 'UTC')

댓글 수: 1

Thank you for your quick answer. The datetime solution is working fine. I have also reported the 'assignment bug' to Mathworks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2017년 1월 10일

댓글:

2017년 1월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by