MATLAB Answers

Trouble converting table to scatterhistogram

2 views (last 30 days)
Saar Peles
Saar Peles on 17 Sep 2020
Edited: John D'Errico on 17 Sep 2020
Hi I'm getting a weird error when converting a table into a scatterhistogram. I want the rr_la values to be on the same line on the y-axis in two separate parallel data sets for S10 and S12. The regions will just be color coded.
s = scatterhistogram(tablerr_la,'subjects','rr_la','GroupVariable','segments');
The "tablerr_la" in question looks like this:
tablerr_la =
32×3 table
subjects rr_la segments
________ __________ ________
'S10' -0.030551 'basal'
'S10' -0.040102 'basal'
'S10' 0.0016109 'basal'
'S10' -0.020057 'basal'
'S10' -0.033282 'basal'
'S10' -0.024207 'basal'
'S10' -0.050507 'mid'
'S10' -0.020694 'mid'
'S10' -0.020932 'mid'
'S10' -0.035626 'mid'
'S10' -0.081229 'mid'
'S10' -0.023346 'mid'
'S10' -0.026452 'apex'
'S10' -0.017935 'apex'
'S10' -0.037958 'apex'
'S10' -0.0082094 'apex'
'S12' -0.084489 'basal'
'S12' -0.013217 'basal'
'S12' -0.044645 'basal'
'S12' -0.033263 'basal'
'S12' -0.061952 'basal'
'S12' -0.10665 'basal'
'S12' -0.053985 'mid'
'S12' -0.017043 'mid'
'S12' -0.041353 'mid'
'S12' -0.043656 'mid'
'S12' -0.061401 'mid'
'S12' -0.033157 'mid'
'S12' 0.0051804 'apex'
'S12' -0.0054823 'apex'
'S12' -0.071557 'apex'
'S12' -0.043434 'apex'
The error I get when compiling is this:
>> StrainPlots
Error using scatterhistogram (line 82)
Expected XData to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, categorical
Error in StrainPlots (line 60)
s = scatterhistogram(tablerr_la,'subjects','rr_la','GroupVariable','segments');
There is also no such line as line 82 but thats part of my issue.

  1 Comment

John D'Errico
John D'Errico on 17 Sep 2020
The error was in scatterhistogram, line 82 of that code. (Yes, there are 82 lines in that function. In fact, it has more than 200 lines.) The error arises because you are passing that function data of a class it did not expect.
That is, two of the columns in your table are character strings, not categorical values.
You can convert them into categorical variables using:
help categorical
For example:
ans =
1×3 categorical array
S10 S12 S10

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!