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

조회 수: 3 (최근 30일)
Sadiq Akbar
Sadiq Akbar 2021년 1월 21일
댓글: Sadiq Akbar 2021년 1월 21일
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
dpb
dpb 2021년 1월 21일
clear all
close all
are the problem
Sadiq Akbar
Sadiq Akbar 2021년 1월 21일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 1월 21일
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
Sadiq Akbar
Sadiq Akbar 2021년 1월 21일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by