Overwrite Column Values based on index derived using another colum of the same table
Show older comments
I am working with the table that contains 5 string columns. Based on index of column 2 I need to replace values in column 3. This is the code that I have AssetClassesTable.SecType(strfind(AssetClassesTable.AssetSuperClass,'CASH'))={'Cash'}:
However, I am getting the following error: Table row subscripts must be real positive integers, logicals, strings, or cell arrays of strings.
I've tried to play around with the different brackets, but no luck.
AS a recap, I am looking to identify rows of column AssetSuperClass that contain text 'CASH', then use index for these rows to overwrite '' (blanks) in Column SecType.
Any help would be greatly appreciated. Thanks.
Answers (1)
Peter Perkins
on 17 Feb 2017
Try using strcmp instead of strfind. strcmp will create a logical vector.
But also: AssetSuperClass aqnd SecType sound like a candidates for using categorical variables, at which point the command would become
AssetClassesTable.SecType(AssetClassesTable.AssetSuperClass == 'CASH')) = 'Cash'
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!