AppDesigner Converting Table Data to Categorical Supported?
Show older comments
I am importing data from a .csv file and need to convert one of the columns to categorical variables. Conversion of Table data to categorical variables using the below code does not work in appdesigner
Data.IncludedInDistribution_=categorical(Data.IncludedInDistribution_);
The returned error is:
Struct contents reference from a non-struct array object.
Is there a work around?
Accepted Answer
More Answers (2)
David Ding
on 18 Oct 2017
Edited: David Ding
on 19 Oct 2017
0 votes
Hi Josh,
I see that you are importing data from CSV file and trying to create a categorical array from it. Without knowing the details about the import itself, I will try to comment on the root cause of the error and possible workaround.
The error you are receiving is because the input argument, "Data.IncludedInDistribution_" is not one of the acceptable data types for the "categorical" function:
For example, if "Data.IncludedInDistribution_" is a table, which is not one of the acceptable data types, then you may use "table2cell" function to convert it into a cell array (which is one of the acceptable data types) first prior to calling "categorical".
Hope this helps.
Cheers,
David
Peter Perkins
on 19 Oct 2017
0 votes
Without meaning to contradict David, a cell array is only one of many different inputs that the categorical function will accept. The input is NOT required to be a cell array. But it's impossible to say what's happening without knowing what you are passing in.
So, what type is Data.IncludedInDistribution_?
4 Comments
David Ding
on 19 Oct 2017
Hi Peter,
Thanks for the correction. You are right--in addition to cell array "categorical" can also take in other data types such as numerical arrays. However, in the documentation it does not take in a "table" as an acceptable data type. Therefore, if the type of "Data.IncludedInDistribution_" is a table, then it needs to be converted into one of the acceptable data type before calling "categorical".
I will edit my original response to reflect this.
Sincerely,
David
Joshua Welsh
on 19 Oct 2017
David Ding
on 19 Oct 2017
Thanks Josh! Do you mind sharing your code for the part where you import the CSV file and up to the line:
Data.IncludedInDistribution_=categorical(Data.IncludedInDistribution_);
Where the error occurred?
Sincerely,
David
Joshua Welsh
on 19 Oct 2017
Edited: Joshua Welsh
on 19 Oct 2017
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!