how to plot multiple cdf plots in one figure?
Mostra commenti meno recenti
i have a matrix in excel file in which i want to draw cdf for each column in a single figure. Help required asap. Or how to plot multiple vectors in one cdf plot?
Risposte (1)
Image Analyst
il 15 Feb 2014
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(grayImage, []);
caption = sprintf('%s (Original Grayscale Image)', baseFileName);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Get the histogram of every 10th column and plot it.
subplot(1, 2, 2);
for column = 1 : 10 : columns
thisColumn = grayImage(:, column);
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(thisColumn);
cdf = cumsum(pixelCount) / numel(thisColumn);
plot(cdf, 'b-', 'Color', rand(1,3), 'LineWidth', 2);
if column == 1
hold on;
end
end
grid on;
title('CDF of columns', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

27 Commenti
Muhammad awan
il 16 Feb 2014
Muhammad awan
il 16 Feb 2014
Image Analyst
il 16 Feb 2014
In my code, line 49 is this:
% Check if file exists.
and I ran it again and it ran fine, so that tells me that you modified my code and somehow made it not work. I can't tell how you broke it unless I see what you did.
If you just want the cdfs of 3 particular columns, then you can do that. Just extract 3 columns:
column1Profile = grayImage(:, column1);
column2Profile = grayImage(:, column2);
column3Profile = grayImage(:, column3);
then call hist and cumsum on each profile.
Muhammad awan
il 17 Feb 2014
Muhammad awan
il 17 Feb 2014
Image Analyst
il 17 Feb 2014
You must have called your m-file cdf, didn't you? That may cause the error. It's probably trying to call your m-file instead of using the variable by the same name. What does this show?
which -all cdf
Rename one of them, either the m-file or the variable.
Muhammad awan
il 17 Feb 2014
Image Analyst
il 17 Feb 2014
Yes, pretty much like mine except for only 4 curves. It should be trivial for you to adapt my code to take the cdf of only the 4 columns that you want.
Muhammad awan
il 17 Feb 2014
Muhammad awan
il 17 Feb 2014
Image Analyst
il 17 Feb 2014
Modificato: Image Analyst
il 18 Feb 2014
By figure, I thought you meant image. So just use xlsread and plot, something like (untested)
numbers = xlsread('cdf.slxs');
cdf1 = cumsum(numbers(:,1)) / sum(numbers(:,1));
cdf2 = cumsum(numbers(:,2)) / sum(numbers(:,2));
cdf3 = cumsum(numbers(:,3)) / sum(numbers(:,3));
plot(cdf1, 'b-', 'LineWidth', 2);
hold on;
plot(cdf2, 'r-', 'LineWidth', 2);
plot(cdf3, 'g-', 'LineWidth', 2);
Muhammad awan
il 17 Feb 2014
Muhammad awan
il 17 Feb 2014
Image Analyst
il 17 Feb 2014
Examine the variables in the debugger: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ Are they correct?
Muhammad awan
il 18 Feb 2014
Muhammad awan
il 18 Feb 2014
Image Analyst
il 18 Feb 2014
What is cdfplot()? I thought you were using plot(). Is cdfplot the name of your m file? Please give the exact error message - don't snip or paraphrase.
Muhammad awan
il 18 Feb 2014
Muhammad awan
il 18 Feb 2014
Muhammad awan
il 18 Feb 2014
Image Analyst
il 18 Feb 2014
Take out the 'Color' option.
Muhammad awan
il 18 Feb 2014
Muhammad awan
il 18 Feb 2014
Muhammad awan
il 18 Feb 2014
Image Analyst
il 18 Feb 2014
Examine them in the debugger to see if they're all the same.
Muhammad awan
il 18 Feb 2014
Muhammad awan
il 18 Feb 2014
Categorie
Scopri di più su Noncentral t Distribution in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
