Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting data to use #8

Open
misslitty opened this issue Jul 19, 2018 · 5 comments
Open

Formatting data to use #8

misslitty opened this issue Jul 19, 2018 · 5 comments

Comments

@misslitty
Copy link

Hi, your plot looks beautiful. This is a basic issue, but how should data be formatted for the program to run properly?

I currently have three groups, CCC, FFF, VVV, entered in a format such as CCC = [12 14 23 34 54 25];
This is not running properly and I am wondering how I should be entering these values instead so that I can get it to run.

Sorry for the stupid question, and any help is much appreciated!

@bastibe
Copy link
Owner

bastibe commented Jul 20, 2018

Violinplot is supposed to work the same way as box plots. If in doubt, try the example in the readme, and format your data the same way.

If you then still need my help, please post a complete, executable code fragment and the error it produces.

@misslitty
Copy link
Author

I don't know why I'm struggling with this so much. I've tried it a few different ways. The CCC, FFF, and VVV are my three groups, and MatlabDwellTimes was an Excel doc that I imported, it has the same values, just arranged into three columns for the corresponding group. Even just trying the violinplot function for one group (i.e. CCC) would not work.

CCC = [ 293 234 234 234 236 273 305 305 313 416 465 465 537 698 699 727 784 787 838 1072 1208 1232 1237 1246 1290 1311 1342 1473 1544 1562 1562 1566 1568 1729 1767 1793 1815 1969 2013 2209 2222 2225 2305 2441 3158 3384 3609 3655 3748 3762 3855 4632 4933 6139 6391 6911 6936 7217 11325 14902 16330 18129 ];
FFF = [ 167 176 176 180 183 188 189 207 332 346 369 371 372 394 509 526 549 620 628 693 827 838 859 1078 1187 1206 1217 ];
VVV = [ 305 307 913 1109 1133 1331 1603 1821 2113 3186 3246 3307 3563 4598 4876 8337 18806 ];

data = [CCC,FFF,VVV];
cat = ['CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC';'FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF';'VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV'];
%%
% violinplot(data,cat)

violinplot(MatlabDwellTimes)

The error message says "Error in ViolinWork (line 11)
violinplot(MatlabDwellTimes)"

@bastibe
Copy link
Owner

bastibe commented Jul 21, 2018

Thank you. There are two problems in your code, the way you showed it here. Both are in the line that begins with cat = [...:

  1. Since these are strings, the [ operator will concatenate them together. ['CCC', 'CCC', 'CCC'] will result in 'CCCCCCCCC'. This is not what you want. Use {'CCC', 'CCC', ... } instead to make a cell array of strings.
  2. There are two ; in that long list. cat needs to have the same size as data. Replace these ; with ,.

With these two modifications, your example works on my machine:

CCC = [ 293 234 234 234 236 273 305 305 313 416 465 465 537 698 699 727 784 787 838 1072 1208 1232 1237 1246 1290 1311 1342 1473 1544 1562 1562 1566 1568 1729 1767 1793 1815 1969 2013 2209 2222 2225 2305 2441 3158 3384 3609 3655 3748 3762 3855 4632 4933 6139 6391 6911 6936 7217 11325 14902 16330 18129 ];
FFF = [ 167 176 176 180 183 188 189 207 332 346 369 371 372 394 509 526 549 620 628 693 827 838 859 1078 1187 1206 1217 ];
VVV = [ 305 307 913 1109 1133 1331 1603 1821 2113 3186 3246 3307 3563 4598 4876 8337 18806 ];

data = [CCC,FFF,VVV];
cat = {'CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','CCC','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','FFF','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV','VVV'};
violinplot(data,cat)

@misslitty
Copy link
Author

I appreciate it so much!
When I run that code, I am getting the same error message "Error in DwellTime (line 25) violinplot(data,cat)"

@bastibe
Copy link
Owner

bastibe commented Jul 23, 2018

The above code works on my computer. If you paste the exact code above into your Matlab, does it not work? What version of Matlab are you running?
But honestly, chances are that your code is subtly different from the above example. Make sure that size(data) and size(cat) are identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants