how to merge two array into single histogram in matlab - matlab

I want to compare two histogram.
In array A and B there are 50 values.
I want to show them in to one histogram using different color for A and B plot in matlab.
This is my current code:
load iris.txt;
A=iris(:,1);
B=iris(:,2);
Can anyone help me to do that?

Just put all your data in a matrix
for example:
figure
rng(0,'twister')
data = randn(1000,3);
hist(data)

Related

Using Matlab's histogram() to simultaneously plot two sets of data

I have an matrix A containing two columns for two sets of data. I want to plot these on the same histogram, using different colors for the bars representing the class intervals. I can do this using hist(A), in which case each column in the matrix is taken as a distinct set of data. I would like to use histogram() instead, and also define edges for bins. How can I do this?
The answer is simpler than I thought:
histogram(A(:,1))
hold on
histogram(A(:,2))
This automatically makes the bars transparent, so both can be seen.

Matlab get an average plot out of several plot

I'm just getting started with matlab and I'm trying to plot some graph with it.
The problem is I don't know how to get the average data out of 10 plot().
Can anyone guide me for it? Thank you :)
Assuming you don't have access to the original data you used for doing the plots:
plot_data = get(get(gca,'Children'),'YData'); % cell array of all "y" data of plots
average = mean(cell2mat(plot_data));
In order for this to work, you have to use this code right after doing the plots, that is, without plotting to any other figure (gca is a handle to the current axes).
Assume your data is stored row-wise in a m x n matrix A, with n columns corresponding to different values of the continuous error, and m rows corresponding to different curves. Then to inspect the mean over the curves just use
Amean = mean(A,1);
plot(Amean)
Please take a look at this link: it solve my problem getting the average plot.
https://www.mathworks.com/matlabcentral/fileexchange/27134-plot-average-line
After downloading the files just put those script on your working folder and add this line to your script.
plotAverage(gca,[],'userobustmean',0)

MATLAB: plotting multiple columns of a matrix

Inside a MATLAB function I have built a matrix A, whose dimensions M and N are set as parameters of the function. I would like to plot all the columns of this matrix, given a vector of indices B with length M. Hence, I use these lines:
figure
plot(B,A)
I specified figure as the MATLAB function returns more different plots.
My problem is that the program plots just two columns of the matrix with different colours (blue and violet). Where is my mistake?
Thank you for your attention.
go for
plot(repmat(B,1,N),A);
or
plot(repmat(B,N,1),A);
(depending on your rows/columns). You need to have same size matrices in plot.
Moreover, if B are just consecutive indexes, you may want to consider Plot(A) (or Plot(A')).
I noticed that there was an error which caused the overlap of the different curves, so the way which I used to plot the colums of a matrix is valid. However, the method proposed by Acorbe is a possibility, too.

assigning values to a few cells from a vector

I have a cell array and a vector, and I want to assign each coordinate of the vector to a different cell, in the same location.
For example, the j coordinate in a vector becomes the (k,l) coordinate in the (j,1) cell. In pseudo matlab it would look like this:
myCell{:,1}(k,l)=myVector;
Is there a good way to do that without just looping? (performance is an issue.)
a small example:
myCell=cell(2,4);
myV=[1;2];
%what I wish to change:
for j=1:size(myV,1)
myCell{j,1}(1,1)=myV(j)
end
Thanks in advance!
Depending on the data type in your myVector you'll end up using one of the two following commands.
mat2cell or num2cell
The help pages in Matlab give great detail on the different ways to call the functions, just in case you want to do some fancy grouping of the data and such.
mat2cell: http://www.mathworks.com/help/techdoc/ref/mat2cell.html
num2cell: http://www.mathworks.com/help/techdoc/ref/num2cell.html
Sample Code:
myCell=cell(2,4);
myV=[1;2];
% %what I wish to change:
% for j=1:size(myV,1)
% myCell{j,1}(1,1)=myV(j)
% end
myCell(:,1) = num2cell(myV);

OpenCV: Creating a histogram from a number of float arrays

I have a number of float arrays, and my purpose is to create a histogram for them. I want to get a graph of the values' frequencies - one graph per each array. and I need all the graphs to be shown on the same window, like this Opencv example does for rgb color histogram. I'm looking for a way to do it using OpenCv or to dump the values out to a file and do the histogram using Matlab. Any idea?
Matlab has a built-in histogram function - hist. It can calculate the histogram, or plot it, or both. For example, if f is a list of files with data you can use
for i=1:length(f)
d=importdata(f(i));
subfigure(length(f),1,i);
hist(d);
end
(Of course, you have to tweak the data importing thingy to make it work. I don't know what the format of your data is in)