Issue with box plot code or something else?????
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sadiq Akbar
el 21 de En. de 2021
Comentada: Sadiq Akbar
el 21 de En. de 2021
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 comentarios
Respuesta aceptada
Cris LaPierre
el 21 de En. de 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';
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!