Issue with box plot code or something else?????

1 view (last 30 days)
I have two sets of mat files. In 1st set, I have 2sn0_sorted, 3sn0_sorted and 4sn0_sorted. In 2nd set, these are 2sn0, 3sn0 and 4sn0. I have the following Matlab code to plot box plot:
clear all
close all
clc
load 2sn0_sorted
fitness2sn0=one;
load 3sn0_sorted
fitness3sn0=one;
load 4sn0_sorted
fitness4sn0=one;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Descending Order
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fitness2sn0=sort(fitness2sn0,'descend');
fitness3sn0=sort(fitness3sn0,'descend');
fitness4sn0=sort(fitness4sn0,'descend');
figure
h1=boxplot([fitness2sn0; fitness3sn0; fitness4sn0].');
set(h1,{'linew'},{2})
grid
Ax = gca;
Ax.XLabel.String = '\bf No. of Sources';
Ax.YLabel.String = '\bf fitness';
Ax.YScale = 'log';
Ax.XTickLabel = compose('%ds',2:4);
Ax.YLim = [1E-30 10];
title('\bf Fitness of different sources with no noise')
set(gca,'linew',2)
When I run the above program and it works well. But when I load my 2nd set of mat files and run the same program, it only displays one plot.
Whats the problem? My mat files are attached herewith.
  2 Comments
Sadiq Akbar
Sadiq Akbar on 21 Jan 2021
Thank you very much dear dpb for your response. But I think this is not the problem because if this were the problem then (1) it must have behaved the same with the 1st set of mat files as well (2) even if we comment these commands, it still behaves the same with the 2nd set of mat files.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 21 Jan 2021
The problem is the your variable one in 2sn0_sorted, 3sn0_sorted, and 4sn0_sorted are row vectors, of dimension 1x100. You vertically concatenate them in the boxplot command (using a semicolon), to create a 3x100 array, which is then transposed to create a 100x3. Each column becomes a boxplot.
However, in 2sn0, 3sn0, and 4sn0, your variable one is a 100x1 column vector. You process the data the same, though, so now vertically concatenating them creates a 300x1 vector, which is then transposed to a 1x300. Since it is vector, MATLAB assumes all values go in the same plot.
If you want to use the same code to process the differend data sets, you will need to make sure your data is arranged the same in all of them. A quick fix is to transpose the data at the beginning for the unsorted cases.
S1=load('2sn0','one');
fitness2sn0=S1.one';
S2=load('3sn0','one');
fitness3sn0=S2.one';
S3=load('4sn0','one');
fitness4sn0=S3.one';
  1 Comment
Sadiq Akbar
Sadiq Akbar on 21 Jan 2021
Thank you very much dear Cris LaPierre. Indeed you are right. After insering your piece of code, it worked very well. Thank you once again.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!