tall array assignment with tall logical vector
4 次查看(过去 30 天)
显示 更早的评论
"( )" 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 个评论
Edric Ellis
2017-1-11
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
2017-1-10
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Tall Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!