Code covered by the BSD License  

Highlights from
Rosin-Rammler Diagram plotting tool

image thumbnail

Rosin-Rammler Diagram plotting tool

by

 

25 Jun 2010 (Updated )

This tool plots the Rosin-Rammler Diagram (RRSB) and calculates various related parameters.

calculator(varargin)
function varargout = calculator(varargin)
%% MATLAB(R) tool for plotting Rosin-Rammler size distribution diagram
%
%                 Ivan Brezani (a) and Fridrich Zelenak
%
%                   Technical University of Kosice,
%                            BERG Faculty,
%     Institute of Montanneous Sciences and Environmental Protection
%
%                      Last updated: 2010-07-27
%
% 
% (a) ivan.brezani@tuke.sk
% 

% Copyright (c) 2010, Ivan Brezani
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without 
% modification, are permitted provided that the following conditions are 
% met:
%
%    * Redistributions of source code must retain the above copyright 
%      notice, this list of conditions and the following disclaimer.
%    * Redistributions in binary form must reproduce the above copyright 
%      notice, this list of conditions and the following disclaimer in 
%      the documentation and/or other materials provided with the distribution
%    * Neither the name of the University Paris Sud nor the names 
%      of its contributors may be used to endorse or promote products derived 
%      from this software without specific prior written permission.
%      
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
% POSSIBILITY OF SUCH DAMAGE.

% CALCULATOR M-file for calculator.fig
%      CALCULATOR, by itself, creates a new CALCULATOR or raises the existing
%      singleton*.
%
%      H = CALCULATOR returns the handle to a new CALCULATOR or the handle to
%      the existing singleton*.
%
%      CALCULATOR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CALCULATOR.M with the given input arguments.
%
%      CALCULATOR('Property','Value',...) creates a new CALCULATOR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before calculator_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to calculator_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help calculator

% Last Modified by GUIDE v2.5 11-Mar-2010 10:03:48

% Begin initialization code - DO NOT EDIT

%% MATLAB(R) tool for plotting Rosin-Rammler size distribution diagram
%
%                 Ivan Brezani (a) and Fridrich Zelenak
%
%                   Technical University of Kosice,
%                            BERG Faculty,
%     Institute of Montanneous Sciences and Environmental Protection
%
%                      Last updated: 2010-07-09
%
% 
% (a) ivan.brezani@tuke.sk
% 

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @calculator_OpeningFcn, ...
                   'gui_OutputFcn',  @calculator_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before calculator is made visible.
function calculator_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to calculator (see VARARGIN)

% Choose default command line output for calculator
handles.output = hObject;

if handles.open == 1
    
    J=1;
    d1_c=[];
    data1_c=[];
    for I=1:80
        if isnan(handles.d1_c(I))==1 || isnan(handles.retained_1_c(I))==1

        else
            d1_c(J) = handles.d1_c(I)*handles.units_1_c(I);
            data1_c(J) = handles.retained_1_c(I);
            J=J+1;
        end
    end

    J=1;
    d2_c=[];
    data2_c=[];
    for I=1:80
        if isnan(handles.d2_c(I))==1 || isnan(handles.retained_2_c(I))==1

        else
            d2_c(J) = handles.d2_c(I)*handles.units_2_c(I);
            data2_c(J) = handles.retained_2_c(I);
            J=J+1;
        end
    end

    J=1;
    d3_c=[];
    data3_c=[];
    for I=1:80
        if isnan(handles.d3_c(I))==1 || isnan(handles.retained_3_c(I))==1

        else
            d3_c(J) = handles.d3_c(I)*handles.units_3_c(I);
            data3_c(J) = handles.retained_3_c(I);
            J=J+1;
        end
    end
    
    if handles.fit_eq_c == 0 || handles.fit_eq_c == 1 
    else
        handles.fit_eq_c = 0;
    end
    
    if handles.fit_eq_c == 0;
    
        d1 = log10(d1_c);
        d2 = log10(d2_c);
        d3 = log10(d3_c);
        
        data1 = log10(log10(100./data1_c));
        data2 = log10(log10(100./data2_c));
        data3 = log10(log10(100./data3_c));
        
        % Calculate linear fitting
        if length(d1)>=2
            fit1 = polyfit(d1,data1,1);
            handles.n1 = (data1(length(data1)) - data1(1))/(d1(length(d1))-d1(1));
        else
            fit1 = [0 0];
            handles.n1 = NaN;
        end
        handles.fit1 = fit1;
        data1 = (d1.*fit1(1))+fit1(2);

        if length(d2)>=2
            fit2 = polyfit(d2,data2,1);
            handles.n2 = (data2(length(data2)) - data2(1))/(d2(length(d2))-d2(1));
        else
            fit2 = [0 0];
            handles.n2 = NaN;
        end
        handles.fit2 = fit2;
        data2 = (d2.*fit2(1))+fit2(2);

        if length(d3)>=2
            fit3 = polyfit(d3,data3,1);
            handles.n3 = (data3(length(data3)) - data3(1))/(d3(length(d3))-d3(1));
        else
            fit3 = [0 0];
            handles.n3 = NaN;
        end
        handles.fit3 = fit3;
        data3 = (d3.*fit3(1))+fit3(2);

        % calculated Rd back to %
        data1 = 100./(10.^(10.^data1));
        data2 = 100./(10.^(10.^data2));
        data3 = 100./(10.^(10.^data3));
        
        corr1 = corrcoef(data1_c, data1);
        corr2 = corrcoef(data2_c, data2);
        corr3 = corrcoef(data3_c, data3);
        
        handles.corr1 = corr1(1, 2);
        handles.corr2 = corr2(1, 2);
        handles.corr3 = corr3(1, 2);

        di1 = (log10(log10(100/(100/exp(1))))-fit1(2))/fit1(1);
        di2 = (log10(log10(100/(100/exp(1))))-fit2(2))/fit2(1);
        di3 = (log10(log10(100/(100/exp(1))))-fit3(2))/fit3(1);
        
        handles.di1 = 10^di1;
        handles.di2 = 10^di2;
        handles.di3 = 10^di3;
        
        d1_3679 = handles.di1;
        d1_80 = handles.di1*((-1*log(20/100))^(1/handles.n1));
        n = handles.n1;
        
    else
        if length(d1_c) >= 2
            x = real(lsqcurvefit(@(x,d1_c) rosin(x,d1_c),[1;1],d1_c,data1_c));
            d1_3679 = x(1);
            d1_80 = x(1)*((-1*log(20/100))^(1/x(2)));
            data1_exp = rosin(x,d1_c);
            corr1 = corrcoef(data1_c,data1_exp);
            handles.corr1 = corr1(1, 2);
            n = x(2);
            handles.n1 = n;
            handles.di1 = x(1);
        else
            d1_3679 =  Inf;
            d1_80 = Inf;
            handles.corr1 = NaN;
            n = NaN;
            handles.n1 = NaN;
            handles.di1 = Inf;
        end
        
        if length(d2_c) >= 2
            x = real(lsqcurvefit(@(x,d2_c) rosin(x,d2_c),[1;1],d2_c,data2_c));
            data2_exp = rosin(x,d2_c);
            corr2 = corrcoef(data2_c,data2_exp);
            handles.corr2 = corr2(1, 2);
            handles.n2 = x(2);
            handles.di2 = x(1);
        else
            handles.corr2 = NaN;
            handles.n2 = NaN;
            handles.di2 = Inf;
        end
        
        if length(d3_c) >= 2
            x = real(lsqcurvefit(@(x,d3_c) rosin(x,d3_c),[1;1],d3_c,data3_c));
            data3_exp = rosin(x,d3_c);
            corr3 = corrcoef(data3_c, data3_exp);
            handles.corr3 = corr3(1, 2);
            handles.n3 = x(2);
            handles.di3 = x(1);
        else
            handles.corr3 = NaN;
            handles.n3 = NaN;
            handles.di3 = Inf;
        end
    end
        
    % Show data
    
    handles.Rdd_e = 36.79;
    handles.Rdd_t = d1_3679;
    set(handles.edit1, 'String', num2str(handles.Rdd_e));
    set(handles.text1, 'String', num2str(handles.Rdd_t));
    handles.dRd_e = d1_80;
    handles.dRd_t = 20;
    set(handles.edit2, 'String', num2str(handles.dRd_e));
    set(handles.text2, 'String', num2str(handles.dRd_t));
    set(handles.text5, 'String', num2str(handles.corr1));
    set(handles.text6, 'String', num2str(handles.corr2));
    set(handles.text7, 'String', num2str(handles.corr3));
        
    % Calculate n for Rosin-Rammler Distribution
    
    n = ['Calculated Rosin-Rammler equation parameters are: d" = ', num2str(d1_3679), ' [mm] and parameter n = ', num2str(n), '.']; 
    uiwait(helpdlg(n, 'Calculated Parameters'));
    
end

    handles.open = 0;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes calculator wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = calculator_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
if isnan(str2double(get(hObject,'String'))) == 1
    uiwait(errordlg('Please enter numerical value', 'Error', 'Modal'));
    set(hObject, 'String', num2str(handles.Rdd_e));
elseif str2double(get(hObject,'String')) >= 100 || str2double(get(hObject,'String')) <= 0
    uiwait(errordlg('Please enter value between 0 and 100 [%]', 'Error', 'Modal'));
    set(hObject, 'String', num2str(handles.Rdd_e));
else
    if handles.data_n ==1
        handles.Rdd_e = str2double(get(hObject,'String'));
        d1_3679 = handles.di1*((-1*log(handles.Rdd_e/100))^(1/handles.n1));
        handles.Rdd_t = d1_3679;
    elseif handles.data_n == 2
        handles.Rdd_e = str2double(get(hObject,'String'));
        d1_3679 = handles.di2*((-1*log(handles.Rdd_e/100))^(1/handles.n2));
        handles.Rdd_t = d1_3679;
    else
        handles.Rdd_e = str2double(get(hObject,'String'));
        d1_3679 = handles.di3*((-1*log(handles.Rdd_e/100))^(1/handles.n3));
        handles.Rdd_t = d1_3679;
    end
    set(handles.text1, 'String', num2str(handles.Rdd_t)); 
end
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

mainGUIhandle = RRD;
mainGUIdata  = guidata(mainGUIhandle);
handles.d1_c = mainGUIdata.d1;
handles.d2_c = mainGUIdata.d2;
handles.d3_c = mainGUIdata.d3;
handles.retained_1_c = mainGUIdata.retained_1;
handles.retained_2_c = mainGUIdata.retained_2;
handles.retained_3_c = mainGUIdata.retained_3;
handles.units_1_c = mainGUIdata.units_1;
handles.units_2_c = mainGUIdata.units_2;
handles.units_3_c = mainGUIdata.units_3;
handles.open = 1;
handles.data_n = 1;
handles.fit_eq_c = mainGUIdata.fit_eq;

guidata(hObject, handles);

function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
if isnan(str2double(get(hObject,'String'))) == 1
    uiwait(errordlg('Please enter numerical value', 'Error', 'Modal'));
    set(hObject, 'String', num2str(handles.Rdd_e));
else
    if handles.data_n ==1
        handles.dRd_e = str2double(get(hObject,'String'));
        y_av = 100*exp(-1*((handles.dRd_e/handles.di1)^handles.n1));
        handles.dRd_t = y_av;
    elseif handles.data_n == 2
        handles.dRd_e = str2double(get(hObject,'String'));
        y_av = 100*exp(-1*((handles.dRd_e/handles.di2)^handles.n2));
        handles.dRd_t = y_av;
    else
        handles.dRd_e = str2double(get(hObject,'String'));
        y_av = 100*exp(-1*((handles.dRd_e/handles.di3)^handles.n3));
        handles.dRd_t = y_av;
    end
    set(handles.text2, 'String', num2str(handles.dRd_t)); 
end
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(calculator);


% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3
handles.data_n = 1;

    d1_3679 = handles.di1*((-1*log(handles.Rdd_e/100))^(1/handles.n1));
    handles.Rdd_t = d1_3679;
    set(handles.text1, 'String', num2str(handles.Rdd_t)); 
    
    y_av = 100*exp(-1*((handles.dRd_e/handles.di1)^handles.n1));
    handles.dRd_t = y_av;
    set(handles.text2, 'String', num2str(handles.dRd_t));
    
    d1_3679 = handles.di1;   
    n = handles.n1;
    n = ['Calculated Rosin-Rammler equation parameters are: d" = ', num2str(d1_3679), ' [mm] and parameter n = ', num2str(n), '.']; 
    uiwait(helpdlg(n, 'Calculated Parameters'));
        
guidata(hObject, handles);

% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2
handles.data_n = 2;

    d1_3679 = handles.di2*((-1*log(handles.Rdd_e/100))^(1/handles.n2));
    handles.Rdd_t = d1_3679;
    set(handles.text1, 'String', num2str(handles.Rdd_t)); 
    
    y_av = 100*exp(-1*((handles.dRd_e/handles.di2)^handles.n2));
    handles.dRd_t = y_av;
    set(handles.text2, 'String', num2str(handles.dRd_t));
    
    d1_3679 = handles.di2;   
    n = handles.n2;
    n = ['Calculated Rosin-Rammler equation parameters are: d" = ', num2str(d1_3679), ' [mm] and parameter n = ', num2str(n), '.']; 
    uiwait(helpdlg(n, 'Calculated Parameters'));
    
guidata(hObject, handles);

% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
handles.data_n = 3;
    
    d1_3679 = handles.di3*((-1*log(handles.Rdd_e/100))^(1/handles.n3));
    handles.Rdd_t = d1_3679;
    set(handles.text1, 'String', num2str(handles.Rdd_t)); 
    
    y_av = 100*exp(-1*((handles.dRd_e/handles.di3)^handles.n3));
    handles.dRd_t = y_av;
    set(handles.text2, 'String', num2str(handles.dRd_t));
    
    d1_3679 = handles.di3;   
    n = handles.n3;
    n = ['Calculated Rosin-Rammler equation parameters are: d" = ', num2str(d1_3679), ' [mm] and parameter n = ', num2str(n), '.']; 
    uiwait(helpdlg(n, 'Calculated Parameters'));
    
guidata(hObject, handles);

function F = rosin(x,d_data)
%ROSIN Summary of this function goes here
%   Detailed explanation goes here
F=100.*exp(-1.*((d_data./x(1)).^x(2)));

Contact us