How to make a valid array for boxplots?

2 Ansichten (letzte 30 Tage)
Emma Wistaff
Emma Wistaff am 11 Aug. 2017
Bearbeitet: José-Luis am 11 Aug. 2017
Hello, I am trying to make a boxplot in MATLAB using imported Excel data. I have the two columns of data I wish to plot, both are a cell arrays, one called Juice_type which has names such as 'Orange', 'Apple', 'Kiwi' (297x1). The other is numerical data, titled Area_Glu2(297x1). When I run the script it gives me the error 'Input (x) does not appear to be a valid array.'. My end goal is to have a boxplot with the 6 different Groups in Juice_type on the xaxis and the Areas on yaxis. I am a relatively new user to MATLAB and might be missing a key line that may solve this Problem. I am wondering how to make the c3 variable a valid Array to plot.
Here is my script:
%%Define Elements
c1 = Area_Glu2 ; %A 297x1 cell
c2 = Juice_type; %A 297x1 cell
c3 = ([c2, c1]); %Makes a 297x2 Cell array
boxplot(c3);
Edit: Here is my script from the first attempt. The data is all the same cell arrays. Maybe this one is easier to fix? It outputs a boxplot but I Need to edit it, such as boxstyle and colouring but it gives me a structure error when I try to add Name/Value additions such as 'BoxStyle', 'filling'
boxplot(Asp, juice_type1);
title('Amino Acid Juice Composition');
xlabel('Juice type');
ylabel('Asp (concentration)');
ylim([-100 2500]);

Antworten (1)

José-Luis
José-Luis am 11 Aug. 2017
Provided an act of God, this might work:
boxplot(cell2mat(c3));
  2 Kommentare
Emma Wistaff
Emma Wistaff am 11 Aug. 2017
I tried this and received a new error,
'All contents of the input cell array must be of the same data type.'
The exact type of boxplot I wish to output is on the MATLAB documentation page in this link titled 'Create a box plot for Grouped variables'. https://www.mathworks.com/help/stats/boxplot.html#bu3pip4
I have tried the same way and it does output a boxplot but not the one I want. When I try to add Name/Value pairs to fix the plot such as changing the filling or colour of it, it does not let me do so. It gives a structure error. Example, changing the script below to boxplot(Asp, juice_type1, 'BoxStyle', 'filled'); it gives me the struct error.
Here is my script for the first attempt. The posted question and script is my second script attempt at avoiding structural errors. The data is all the same cell arrays. Maybe this one is easier to fix?
boxplot(Asp, juice_type1);
title('Amino Acid Juice Composition');
xlabel('Juice type');
ylabel('Asp (concentration)');
ylim([-100 2500]);
José-Luis
José-Luis am 11 Aug. 2017
Bearbeitet: José-Luis am 11 Aug. 2017
I don't have your data, I can't see what the error is.
Speculating, which I did in my answer, is an inefficient way to get to a solution.
The error message is pretty self-descriptive though.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by