Trouble Passing Values In App Designer
    8 views (last 30 days)
  
       Show older comments
    
    Kyle McLaughlin
 on 21 Sep 2021
  
    
    
    
    
    Commented: Kyle McLaughlin
 on 30 Dec 2021
            Hi, I have created a Double Dwell Cam Calculator in Matlabs App designer. The app is complete except for one item. I wish to export the profile of the cam, which is just a list of numbers, but a) am having trouble acessing the variable and b)have tried to initialize it prior to where it is used and setting it public using the "properties" drop down. Method b) has allowed the script to run with no errors and exports a text file, however, the text file is empty. Not only is the text file empty, the only place I can find it is in my workspace (that is a problem for a different post perhaps). Does anyone have an idea on how to fix this? The variable I wish to work with is "Cam_Displacement" which first appears on line 371. I try to export it to a text file on line 466. I have also tried to make it a global variable but that didnt help either. I cannot edit the function arguments either, they are grayed out. Any help would be appreciated! Thanks!!! 
classdef Double_Dwell_Cam_Calculator < matlab.apps.AppBase
    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                     matlab.ui.Figure
        TextArea                     matlab.ui.control.TextArea
        CamCharacteristicsandRangesofMotionDegreesPanel  matlab.ui.container.Panel
        Risefrom0toEditFieldLabel    matlab.ui.control.Label
        Risefrom0toEditField         matlab.ui.control.NumericEditField
        DwelltoEditFieldLabel        matlab.ui.control.Label
        DwelltoEditField             matlab.ui.control.NumericEditField
        FalltoEditFieldLabel         matlab.ui.control.Label
        FalltoEditField              matlab.ui.control.NumericEditField
        DwelltoEditField_2Label      matlab.ui.control.Label
        DwelltoEditField_2           matlab.ui.control.NumericEditField
        BaseCircleRadiusinEditFieldLabel  matlab.ui.control.Label
        BaseCircleRadiusinEditField  matlab.ui.control.NumericEditField
        MaxDisplacementinEditFieldLabel  matlab.ui.control.Label
        MaxDisplacementinEditField   matlab.ui.control.NumericEditField
        SCCAFunctionSelectionPanel   matlab.ui.container.Panel
        RisingActionDropDownLabel    matlab.ui.control.Label
        RisingActionDropDown         matlab.ui.control.DropDown
        FallingActionDropDownLabel   matlab.ui.control.Label
        FallingActionDropDown        matlab.ui.control.DropDown
        CalculateCamButton           matlab.ui.control.Button
        SVAJPlotsPanel               matlab.ui.container.Panel
        CamProfilePanel              matlab.ui.container.Panel
        SineConstantCosineAccelerationFunctionDiscriptionsPanel  matlab.ui.container.Panel
        TextArea_2                   matlab.ui.control.TextArea
        TextArea_3                   matlab.ui.control.TextArea
        ExportCamProfileButton       matlab.ui.control.Button
    end
    properties (Access = public)
        Cam_Displacement % displacement profile
    end
    % Callbacks that handle component events
    methods (Access = private)
        % Button pushed function: CalculateCamButton
        function CalculateCamButtonPushed(app, event)
            %Kyle McLaughin
            %Double Dwell Cam Calculator Script
            %Addendum of Cam Calculator Homework for Use in Portfolio
            %Start of code: Get user input
%             disp('The following list contains options for the type of motion for the Rise and Fall')
%             disp('1 = Constant Acceleration')
%             disp('2 = Modified Trap')
%             disp('3 = Simple Harmonic')
%             disp('4 = Mod Sine')
%             disp('5 = Cycloydal')
%             disp('6 = 345 Poly')
%             disp('7 = 4567 Poly')
%             fprintf('Enter the ranges of theta for each segment of the cam:\n')
%             fprintf('Rise from 0 to')
            X_rise = app.Risefrom0toEditField.Value;
            %fprintf('Dwell from %d to',X_rise)
            X_dwellA = app.DwelltoEditField.Value;
            %fprintf('Fall from %d to',X_dwellA)
            X_fall =  app.FalltoEditField.Value;
            %fprintf('Dwell from %d to',X_fall)
            X_dwellB = app.DwelltoEditField_2.Value;
            r= app.BaseCircleRadiusinEditField.Value;
            H_rise = app.MaxDisplacementinEditField.Value;
            app.RisingActionDropDown.ItemsData = [1 2 3 4 5 6 7];
            app.FallingActionDropDown.ItemsData = [1 2 3 4 5 6 7];
            %disp('Select the Equation of Motion for the Rising Action')
            x = app.RisingActionDropDown.Value;
            %disp('Select the Equation of Motion for the Falling Action')
            y = app.FallingActionDropDown.Value;
            %Parameter name
            %1)CONSTANT ACCELERATION
            %2)MODIFIED TRAPEZOID
            %3)SIMPLE HARMONIC
            %4)MODIFIED SINE
            %5)CYCLOYDAL
            %6)3,4,5 POLYNOMIAL DISPLACEMENT
            %7)4,5,6,7 POLYNOMIAL DISPLACEMENT 
            %Constant Parameter Values: each column corresponds to the parameter names
            %above: b(1) = b val for const accel, ***6&7 dont get constant values***
            b=[0,.25,0,.25,.5];
            c=[1,.5,0,0,0];
            d=[0,.25,1,.75,.5];
            C_a=[4,4.8881,4.9348,5.5280,6.2832];
            h = 1;
            beta = 1;
            %Determination of Equation of motion for Rise From User Input
            if x == 1
                n=x;
                %Boundary Conditions
                X_ca1 = linspace(0,.5,length(0:X_rise)/2);
                X_ca2 = linspace(0.5,1,length(0:X_rise)/2);
                %1)CONSTANT ACCELERATION EQUATIONS
                %Application of SCCA curves
                f_z2 = C_a(n).*(((X_ca1.^2)/2) +b(n)*(((1/pi)-.5))*X_ca1 + (b(n)^2)*(.125-(1/(pi.^2))));
                f_z4 = C_a(n).*(((X_ca2.^2)/-2) +((b(n)/pi)+1-(b(n)/2))*X_ca2 + ((2*d(n).^2) - (b(n).^2))*((1/(pi.^2))-(1/8)) - (1/4));
                %Collecting data from the SCCA zones into matrix
                f_curve1 = [f_z2 f_z4(2:length(f_z4))]; 
                %Hr = H_rise*linspace(1,X_rise,length(X_rise:1)); 
                Rise_Segment = [((H_rise*(f_curve1.*h)))] +r;
            elseif x == 2
                    n=x;
                    %Boundary Conditions
                    X_mt1 = linspace(0,.125,length(0:X_rise)/5);
                    X_mt2 = linspace(0.125,0.375,length(0:X_rise)/5);
                    X_mt3 = linspace(0.375,0.625,length(0:X_rise)/5);
                    X_mt4 = linspace(0.625,0.875,length(0:X_rise)/5);
                    X_mt5 = linspace(0.875,1,length(0:X_rise)/5);
                    %2)MODIFIED TRAPEZOID EQUATIONS
                    %Application of SCCA curves
                    f_z1= C_a(n)*((b(n)/pi)*X_mt1-(b(n)/pi).^2*sin((pi/b(n))*X_mt1));
                    f_z2 = C_a(n).*(((X_mt2.^2)/2) +b(n)*(((1/pi)-.5))*X_mt2 + (b(n).^2)*(.125-(1/(pi^2))));
                    f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_mt3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_mt3-((1-d(n))/2))));
                    f_z4= C_a(n)*((-(X_mt4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_mt4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                    f_z5= C_a(n)*((b(n)/pi)*X_mt5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_mt5-1))));
                    %Collecting data from SCCA into matrix
                    f_curve2=[f_z1  f_z2(2:length(f_z2))    f_z3(2:length(f_z3))   f_z4(2:length(f_z4))   f_z5(2:length(f_z5))];
                    %Hr = H_rise*linspace(1,X_rise,length(X_rise:1)); 
                    Rise_Segment = [((H_rise*(f_curve2.*h)))] +r;
            elseif x == 3
                    n=x;
                    %Boundary COnditions
                    %X_sh1 = linspace(0,0,100);
                    X_sh2 = linspace(0,0,length(0:X_rise)/3);
                    X_sh3 = linspace(0,1,length(0:X_rise)/3);
                    X_sh4 = linspace(1,1,length(0:X_rise)/3);
                    %X_sh5 = linspace(1,1,101);
                    %3)SIMPLE HARMONIC EQUATIONS
                    %Application of SCCA curves
                    %f_z1= C_a(n)*((b(n)/pi)*X_sh1-(b(n)/pi).^2*sin((pi/b(n))*X_sh1));
                    f_z2 = C_a(n).*(((X_sh2.^2)/2) +b(n)*(((1/pi)-.5))*X_sh2 + (b(n).^2)*(.125-(1/(pi^2))));
                    f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_sh3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_sh3-((1-d(n))/2))));
                    f_z4= C_a(n)*((-(X_sh4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_sh4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                    %f_z5= C_a(n)*((b(n)/pi)*X_sh5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_sh5-1))));
                    %Colecting Data from SCCA into matrix
                    f_curve3=[f_z2  f_z3    f_z4(2:length(f_z4))];
                    Rise_Segment = [((H_rise*(f_curve3.*h)))] +r;
            elseif x == 4
                    n=x;
                    %Boundary Conditions
                    X_ms1 = linspace(0,0.125,length(0:X_rise)/3);
                    %X_ms2 = linspace(0.125,0.125,100);
                    X_ms3 = linspace(0.125,0.875,length(0:X_rise)/3);
                    %X_ms4 = linspace(0.875,0.875,100);
                    X_ms5 = linspace(0.875,1,length(0:X_rise)/3);
                    %4)MODIFIED SINE EQUATIONS
                    %Application of SCCA curves
                    f_z1= C_a(n)*((b(n)/pi)*X_ms1-(b(n)/pi).^2*sin((pi/b(n))*X_ms1));
                    %f_z2 = C_a(n).*(((X_ms2.^2)/2) +b(n)*(((1/pi)-.5))*X_ms2 + (b(n).^2)*(.125-(1/(pi^2))));
                    f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_ms3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_ms3-((1-d(n))/2))));
                    %f_z4= C_a(n)*((-(X_ms4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_ms4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                    f_z5= C_a(n)*((b(n)/pi)*X_ms5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_ms5-1))));
                    %collecting data from the SCCA zones it into a matrix
                    f_curve4=[f_z1     f_z3         f_z5(2:length(f_z5))];
                    Rise_Segment = [((H_rise*(f_curve4.*h)))] +r;
            elseif x == 5
                    n=x;
                    %Boundary Conditions
                    X_cy1 = linspace(0,.25,length(0:X_rise)/3);
                    %X_cy2 = linspace(0.25,0.25,100);
                    X_cy3 = linspace(0.25,0.75,length(0:X_rise)/3);
                    %X_cy4 = linspace(0.75,0.75,100);
                    X_cy5 = linspace(0.75,1,length(0:X_rise)/3);
                    %5)CYCLOYDAL EQUATION
                    %Application of SCCA curves
                    f_z1= C_a(n)*((b(n)/pi)*X_cy1-(b(n)/pi).^2*sin((pi/b(n))*X_cy1));
                    %f_z2 = C_a(n).*(((X_cy2.^2)/2) +b(n)*(((1/pi)-.5))*X_cy2 + (b(n).^2)*(.125-(1/(pi^2))));
                    f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_cy3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_cy3-((1-d(n))/2))));
                    %f_z4= C_a(n)*((-(X_cy4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_cy4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                    f_z5= C_a(n)*((b(n)/pi)*X_cy5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_cy5-1))));
                    %collecting data from the SCCA zones it into a matrix
                    f_curve5=[f_z1      f_z3      f_z5(2:length(f_z5))];    
                    Rise_Segment = [((H_rise*(f_curve5.*h)))] +r;
            elseif x == 6
                    n=x;
                    bmod = beta*360;
                    theta6 = linspace(0,360,length(0:X_rise));
                    %6)3,4,5 POLYNOMIAL DISPLACEMENT EQUATION
                    f_poly345 = (H_rise*(h*(10*(theta6/bmod).^3-15*(theta6/bmod).^4+6*(theta6/bmod).^5)))+r;
                    Rise_Segment = f_poly345;
            elseif x == 7
                    n=x;
                    bmod = beta*360;
                    theta7 = linspace(0,360,length(0:X_rise));
                    %7)4,5,6,7 POLYNOMIAL DISPLACEMENT EQUATION        
                    f_poly4567 = (H_rise*(h*(35*(theta7/bmod).^4-84*(theta7/bmod).^5+70*(theta7/bmod).^6-20*(theta7/bmod).^7)))+r;
                    Rise_Segment = f_poly4567;
            end
            %Determination of Equation of motion for Fall From User Input
            if y == 1
                n=y;
                %Boundary Conditions
                X_ca1 = linspace(0,.5,length(X_dwellA:X_fall)/2);
                X_ca2 = linspace(0.5,1,length(X_dwellA:X_fall)/2);
                %1)CONSTANT ACCELERATION EQUATION
                %Application of SCCA curves
                f_z2 = C_a(n).*(((X_ca1.^2)/2) +b(n)*(((1/pi)-.5))*X_ca1 + (b(n)^2)*(.125-(1/(pi.^2))));
                f_z4 = C_a(n).*(((X_ca2.^2)/-2) +((b(n)/pi)+1-(b(n)/2))*X_ca2 + ((2*d(n).^2) - (b(n).^2))*((1/(pi.^2))-(1/8)) - (1/4));
                %Collecting data from the SCCA zones it into a matrix
                f_curve1 = [f_z2 f_z4(2:length(f_z4))]; 
                Fall_Segment = flip([((H_rise*(f_curve1.*h)))] +r);
            elseif y == 2
                n=y;
                %Boundary Conditions
                X_mt1 = linspace(0,.125,length(X_dwellA:X_fall)/5);
                X_mt2 = linspace(0.125,0.375,length(X_dwellA:X_fall)/5);
                X_mt3 = linspace(0.375,0.625,length(X_dwellA:X_fall)/5);
                X_mt4 = linspace(0.625,0.875,length(X_dwellA:X_fall)/5);
                X_mt5 = linspace(0.875,1,length(X_dwellA:X_fall)/5);
                %2)MODIFIED TRAPEZOID EQUATION
                %Application of SCCA curves
                f_z1= C_a(n)*((b(n)/pi)*X_mt1-(b(n)/pi).^2*sin((pi/b(n))*X_mt1));
                f_z2 = C_a(n).*(((X_mt2.^2)/2) +b(n)*(((1/pi)-.5))*X_mt2 + (b(n).^2)*(.125-(1/(pi^2))));
                f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_mt3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_mt3-((1-d(n))/2))));
                f_z4= C_a(n)*((-(X_mt4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_mt4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                f_z5= C_a(n)*((b(n)/pi)*X_mt5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_mt5-1))));
                %Collecting data from SCCA into matrix
                f_curve2=[f_z1  f_z2(2:length(f_z2))    f_z3(2:length(f_z3))   f_z4(2:length(f_z4))   f_z5(2:length(f_z5))];
                %Hf = H_fall*linspace(X_dwellA,X_fall,length(X_fall:X_dwellA));  
                Fall_Segment = flip([((H_rise*(f_curve2.*h)))] +r);
            elseif y == 3
                n=y;
                %Boundary COnditions
                %X_sh1 = linspace(0,0,100);
                X_sh2 = linspace(0,0,length(X_dwellA:X_fall)/3);
                X_sh3 = linspace(0,1,length(X_dwellA:X_fall)/3);
                X_sh4 = linspace(1,1,length(X_dwellA:X_fall)/3);
                %X_sh5 = linspace(1,1,101);
                %3)SIMPLE HARMONIC EQUATIONS
                %Application of SCCA curves
                %f_z1= C_a(n)*((b(n)/pi)*X_sh1-(b(n)/pi).^2*sin((pi/b(n))*X_sh1));
                f_z2 = C_a(n).*(((X_sh2.^2)/2) +b(n)*(((1/pi)-.5))*X_sh2 + (b(n).^2)*(.125-(1/(pi^2))));
                f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_sh3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_sh3-((1-d(n))/2))));
                f_z4= C_a(n)*((-(X_sh4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_sh4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                %f_z5= C_a(n)*((b(n)/pi)*X_sh5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_sh5-1))));
                %Colecting Data from SCCA into matrix
                f_curve3=[f_z2  f_z3    f_z4(2:length(f_z4))];
                Fall_Segment = flip([((H_rise*(f_curve3.*h)))] +r);
            elseif y == 4
                n=y;
                %Boundary Conditions
                X_ms1 = linspace(0,0.125,length(X_dwellA:X_fall)/3);
                %X_ms2 = linspace(0.125,0.125,100);
                X_ms3 = linspace(0.125,0.875,length(X_dwellA:X_fall)/3);
                %X_ms4 = linspace(0.875,0.875,100);
                X_ms5 = linspace(0.875,1,length(X_dwellA:X_fall)/3);
                %4)MODIFIED SINE EQUATIONS
                %Application of SCCA curves
                f_z1= C_a(n)*((b(n)/pi)*X_ms1-(b(n)/pi).^2*sin((pi/b(n))*X_ms1));
                %f_z2 = C_a(n).*(((X_ms2.^2)/2) +b(n)*(((1/pi)-.5))*X_ms2 + (b(n).^2)*(.125-(1/(pi^2))));
                f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_ms3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_ms3-((1-d(n))/2))));
                %f_z4= C_a(n)*((-(X_ms4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_ms4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                f_z5= C_a(n)*((b(n)/pi)*X_ms5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_ms5-1))));
                %collecting data from the SCCA zones it into a matrix
                f_curve4=[f_z1     f_z3         f_z5(2:length(f_z5))];
                Fall_Segment = flip([((H_rise*(f_curve4.*h)))] +r);   
            elseif y == 5
                n=y;
                %Boundary Conditions
                X_cy1 = linspace(0,.25,length(X_dwellA:X_fall)/3);
                %X_cy2 = linspace(0.25,0.25,100);
                X_cy3 = linspace(0.25,0.75,length(X_dwellA:X_fall)/3);
                %X_cy4 = linspace(0.75,0.75,100);
                X_cy5 = linspace(0.75,1,length(X_dwellA:X_fall)/3);
                %5)CYCLOYDAL EQUATION
                %Application of SCCA curves
                f_z1= C_a(n)*((b(n)/pi)*X_cy1-(b(n)/pi).^2*sin((pi/b(n))*X_cy1));
                %f_z2 = C_a(n).*(((X_cy2.^2)/2) +b(n)*(((1/pi)-.5))*X_cy2 + (b(n).^2)*(.125-(1/(pi^2))));
                f_z3= C_a(n)*(((b(n)/pi)+(.5*c(n)))*X_cy3+(d(n)/pi).^2 + b(n).^2*(.125-(1/(pi^2)))-(((1-d(n)).^2)/8)-(d(n)/pi).^2*cos((pi/d(n))*(X_cy3-((1-d(n))/2))));
                %f_z4= C_a(n)*((-(X_cy4.^2)/2)+((b(n)/pi)+1-.5*b(n))*X_cy4 + (2*d(n).^2-b(n).^2)*(1/pi^2-.125)-.25);
                f_z5= C_a(n)*((b(n)/pi)*X_cy5+((2*(d(n).^2 - b(n).^2)/pi^2)+(((1-b(n)).^2-d(n).^2)/4)-(b(n)/pi).^2*sin((pi/b(n))*(X_cy5-1))));
                %collecting data from the SCCA zones it into a matrix
                f_curve5=[f_z1      f_z3      f_z5(2:length(f_z5))];    
                Fall_Segment = flip([((H_rise*(f_curve5.*h)))] +r); 
            elseif y == 6
                n=y;
                bmod = beta*360;
                theta6 = linspace(0,360,length(X_dwellA:X_fall));
                %6)3,4,5 POLYNOMIAL DISPLACEMENT EQUATION
                f_poly345 = (H_rise*(h*(10*(theta6/bmod).^3-15*(theta6/bmod).^4+6*(theta6/bmod).^5)))+r;
                Fall_Segment =  flip(f_poly345);
            elseif y == 7
                n=y;
                bmod = beta*360;
                theta7 = linspace(0,360,length(X_dwellA:X_fall));
                %7)4,5,6,7 POLYNOMIAL DISPLACEMENT EQUATION        
                f_poly4567 = (H_rise*(h*(35*(theta7/bmod).^4-84*(theta7/bmod).^5+70*(theta7/bmod).^6-20*(theta7/bmod).^7)))+r;
                Fall_Segment = flip(f_poly4567);
            end
            %creating the dwell displacement values according to user intput
            dwellA = (H_rise*ones(1,length(X_rise:X_dwellA)))+r; 
            dwellB = (ones(1,length(X_fall:X_dwellB))).*r; 
            %collecting displacement data into single matrix 
            Cam_Displacement = [Rise_Segment, dwellA, Fall_Segment, dwellB];
            %differentiation
            theta = linspace(0,360,length(Cam_Displacement));
            velocity = diff(Cam_Displacement(:))./diff(theta(1:length(theta)-1));
            acceleration = diff(velocity)./ diff(theta(1:length(theta)-1));
            jerk = diff(acceleration)./diff(theta(1:length(theta)-1));
            %prints polar plot to panel in UI
            p = polaraxes(app.CamProfilePanel);
            polarplot(p,Cam_Displacement)
            %Plotting SVAJ curves
            t = tiledlayout(app.SVAJPlotsPanel,4,1);
            ax1 = nexttile(t);
            plot(ax1,theta,Cam_Displacement,'b')
            axis (ax1,'auto');
            xlim(ax1,[0 360]);
            xlabel(ax1,'Degrees');
            ylabel(ax1,'in');
            title(ax1,'Displacement');
            ax2 = nexttile(t);
            plot(ax2,theta(1:length(theta)-1),velocity,'r');
            axis (ax2,'auto');
            xlim(ax2,[0 360]);
            title(ax2,'Velocity')
            ylabel(ax2,'in/sec')
            xlabel(ax2,'Degrees')
            ax3 = nexttile(t);
            plot(ax3,theta(1:length(theta)-2),acceleration,'g');
            axis (ax3,'auto');
            xlim(ax3,[0 360]);
            title(ax3,'Acceleration');
            ylabel(ax3,'in/sec^2');
            xlabel(ax3,'Degrees');
            ax4 = nexttile(t);
            plot(ax4,theta(1:length(theta)-3),jerk,'c')
            axis (ax4,'auto');
            xlim(ax4,[0 360]);
            title(ax4,'Jerk')
            ylabel(ax4,'in/sec^3')
            xlabel(ax4,'Degrees')
        end
        % Value changed function: Risefrom0toEditField
        function Risefrom0toEditFieldValueChanged(app, event)
        end
        % Value changed function: DwelltoEditField
        function DwelltoEditFieldValueChanged(app, event)
        end
        % Value changed function: FalltoEditField
        function FalltoEditFieldValueChanged(app, event)
        end
        % Value changed function: DwelltoEditField_2
        function DwelltoEditField_2ValueChanged(app, event)
        end
        % Value changed function: MaxDisplacementinEditField
        function MaxDisplacementinEditFieldValueChanged(app, event)
        end
        % Value changed function: BaseCircleRadiusinEditField
        function BaseCircleRadiusinEditFieldValueChanged(app, event)
        end
        % Button pushed function: ExportCamProfileButton
        function ExportCamProfileButtonPushed(app, event)
            writematrix(app.Cam_Displacement,'Cam_Profile');
        end
    end
    % Component initialization
    methods (Access = private)
        % Create UIFigure and components
        function createComponents(app)
            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 1298 1021];
            app.UIFigure.Name = 'MATLAB App';
            % Create TextArea
            app.TextArea = uitextarea(app.UIFigure);
            app.TextArea.HorizontalAlignment = 'center';
            app.TextArea.FontSize = 34;
            app.TextArea.FontWeight = 'bold';
            app.TextArea.Position = [356 957 588 53];
            app.TextArea.Value = {'Double Dwell Cam Calculator'};
            % Create CamCharacteristicsandRangesofMotionDegreesPanel
            app.CamCharacteristicsandRangesofMotionDegreesPanel = uipanel(app.UIFigure);
            app.CamCharacteristicsandRangesofMotionDegreesPanel.TitlePosition = 'centertop';
            app.CamCharacteristicsandRangesofMotionDegreesPanel.Title = 'Cam Characteristics and Ranges of Motion (Degrees)';
            app.CamCharacteristicsandRangesofMotionDegreesPanel.BackgroundColor = [1 1 1];
            app.CamCharacteristicsandRangesofMotionDegreesPanel.FontWeight = 'bold';
            app.CamCharacteristicsandRangesofMotionDegreesPanel.FontSize = 16;
            app.CamCharacteristicsandRangesofMotionDegreesPanel.Position = [75 527 459 337];
            % Create Risefrom0toEditFieldLabel
            app.Risefrom0toEditFieldLabel = uilabel(app.CamCharacteristicsandRangesofMotionDegreesPanel);
            app.Risefrom0toEditFieldLabel.HorizontalAlignment = 'right';
            app.Risefrom0toEditFieldLabel.Position = [112 269 80 22];
            app.Risefrom0toEditFieldLabel.Text = 'Rise from 0 to';
            % Create Risefrom0toEditField
            app.Risefrom0toEditField = uieditfield(app.CamCharacteristicsandRangesofMotionDegreesPanel, 'numeric');
            app.Risefrom0toEditField.ValueChangedFcn = createCallbackFcn(app, @Risefrom0toEditFieldValueChanged, true);
            app.Risefrom0toEditField.Position = [207 265 110 30];
            % Create DwelltoEditFieldLabel
            app.DwelltoEditFieldLabel = uilabel(app.CamCharacteristicsandRangesofMotionDegreesPanel);
            app.DwelltoEditFieldLabel.HorizontalAlignment = 'right';
            app.DwelltoEditFieldLabel.Position = [144 224 48 22];
            app.DwelltoEditFieldLabel.Text = 'Dwell to';
            % Create DwelltoEditField
            app.DwelltoEditField = uieditfield(app.CamCharacteristicsandRangesofMotionDegreesPanel, 'numeric');
            app.DwelltoEditField.ValueChangedFcn = createCallbackFcn(app, @DwelltoEditFieldValueChanged, true);
            app.DwelltoEditField.Position = [207 220 110 30];
            % Create FalltoEditFieldLabel
            app.FalltoEditFieldLabel = uilabel(app.CamCharacteristicsandRangesofMotionDegreesPanel);
            app.FalltoEditFieldLabel.HorizontalAlignment = 'right';
            app.FalltoEditFieldLabel.Position = [154 183 38 22];
            app.FalltoEditFieldLabel.Text = 'Fall to';
            % Create FalltoEditField
            app.FalltoEditField = uieditfield(app.CamCharacteristicsandRangesofMotionDegreesPanel, 'numeric');
            app.FalltoEditField.ValueChangedFcn = createCallbackFcn(app, @FalltoEditFieldValueChanged, true);
            app.FalltoEditField.Position = [207 179 110 30];
            % Create DwelltoEditField_2Label
            app.DwelltoEditField_2Label = uilabel(app.CamCharacteristicsandRangesofMotionDegreesPanel);
            app.DwelltoEditField_2Label.HorizontalAlignment = 'right';
            app.DwelltoEditField_2Label.Position = [144 141 48 22];
            app.DwelltoEditField_2Label.Text = 'Dwell to';
            % Create DwelltoEditField_2
            app.DwelltoEditField_2 = uieditfield(app.CamCharacteristicsandRangesofMotionDegreesPanel, 'numeric');
            app.DwelltoEditField_2.ValueChangedFcn = createCallbackFcn(app, @DwelltoEditField_2ValueChanged, true);
            app.DwelltoEditField_2.Position = [207 137 110 30];
            % Create BaseCircleRadiusinEditFieldLabel
            app.BaseCircleRadiusinEditFieldLabel = uilabel(app.CamCharacteristicsandRangesofMotionDegreesPanel);
            app.BaseCircleRadiusinEditFieldLabel.HorizontalAlignment = 'right';
            app.BaseCircleRadiusinEditFieldLabel.Position = [64 97 128 22];
            app.BaseCircleRadiusinEditFieldLabel.Text = 'Base Circle Radius (in)';
            % Create BaseCircleRadiusinEditField
            app.BaseCircleRadiusinEditField = uieditfield(app.CamCharacteristicsandRangesofMotionDegreesPanel, 'numeric');
            app.BaseCircleRadiusinEditField.ValueChangedFcn = createCallbackFcn(app, @BaseCircleRadiusinEditFieldValueChanged, true);
            app.BaseCircleRadiusinEditField.Position = [207 93 110 30];
            % Create MaxDisplacementinEditFieldLabel
            app.MaxDisplacementinEditFieldLabel = uilabel(app.CamCharacteristicsandRangesofMotionDegreesPanel);
            app.MaxDisplacementinEditFieldLabel.HorizontalAlignment = 'right';
            app.MaxDisplacementinEditFieldLabel.Position = [67 50 125 22];
            app.MaxDisplacementinEditFieldLabel.Text = 'Max Displacement (in)';
            % Create MaxDisplacementinEditField
            app.MaxDisplacementinEditField = uieditfield(app.CamCharacteristicsandRangesofMotionDegreesPanel, 'numeric');
            app.MaxDisplacementinEditField.ValueChangedFcn = createCallbackFcn(app, @MaxDisplacementinEditFieldValueChanged, true);
            app.MaxDisplacementinEditField.Position = [207 46 110 30];
            % Create SCCAFunctionSelectionPanel
            app.SCCAFunctionSelectionPanel = uipanel(app.UIFigure);
            app.SCCAFunctionSelectionPanel.TitlePosition = 'centertop';
            app.SCCAFunctionSelectionPanel.Title = 'SCCA Function Selection';
            app.SCCAFunctionSelectionPanel.BackgroundColor = [1 1 1];
            app.SCCAFunctionSelectionPanel.FontWeight = 'bold';
            app.SCCAFunctionSelectionPanel.FontSize = 16;
            app.SCCAFunctionSelectionPanel.Position = [75 73 461 125];
            % Create RisingActionDropDownLabel
            app.RisingActionDropDownLabel = uilabel(app.SCCAFunctionSelectionPanel);
            app.RisingActionDropDownLabel.HorizontalAlignment = 'right';
            app.RisingActionDropDownLabel.Position = [102 60 76 22];
            app.RisingActionDropDownLabel.Text = 'Rising Action';
            % Create RisingActionDropDown
            app.RisingActionDropDown = uidropdown(app.SCCAFunctionSelectionPanel);
            app.RisingActionDropDown.Items = {'Constant Acceleration', 'Modified Trapezoid', 'Simple Harmonic', 'Modified Sine', 'Cycloydal', '345 Polynomial', '4567 Polynomial', ''};
            app.RisingActionDropDown.Position = [192 60 166 22];
            app.RisingActionDropDown.Value = 'Constant Acceleration';
            % Create FallingActionDropDownLabel
            app.FallingActionDropDownLabel = uilabel(app.SCCAFunctionSelectionPanel);
            app.FallingActionDropDownLabel.HorizontalAlignment = 'right';
            app.FallingActionDropDownLabel.Position = [100 19 78 22];
            app.FallingActionDropDownLabel.Text = 'Falling Action';
            % Create FallingActionDropDown
            app.FallingActionDropDown = uidropdown(app.SCCAFunctionSelectionPanel);
            app.FallingActionDropDown.Items = {'Constant Acceleration', 'Modified Trapezoid', 'Simple Harmonic', 'Modified Sine', 'Cycloydal', '345 Polynomial', '4567 Polynomial', ''};
            app.FallingActionDropDown.Position = [192 19 166 22];
            app.FallingActionDropDown.Value = 'Constant Acceleration';
            % Create CalculateCamButton
            app.CalculateCamButton = uibutton(app.UIFigure, 'push');
            app.CalculateCamButton.ButtonPushedFcn = createCallbackFcn(app, @CalculateCamButtonPushed, true);
            app.CalculateCamButton.FontSize = 16;
            app.CalculateCamButton.FontWeight = 'bold';
            app.CalculateCamButton.Position = [75 21 213 32];
            app.CalculateCamButton.Text = 'Calculate Cam ';
            % Create SVAJPlotsPanel
            app.SVAJPlotsPanel = uipanel(app.UIFigure);
            app.SVAJPlotsPanel.TitlePosition = 'centertop';
            app.SVAJPlotsPanel.Title = 'SVAJ Plots';
            app.SVAJPlotsPanel.BackgroundColor = [1 1 1];
            app.SVAJPlotsPanel.FontWeight = 'bold';
            app.SVAJPlotsPanel.FontSize = 16;
            app.SVAJPlotsPanel.Position = [690 21 530 495];
            % Create CamProfilePanel
            app.CamProfilePanel = uipanel(app.UIFigure);
            app.CamProfilePanel.TitlePosition = 'centertop';
            app.CamProfilePanel.Title = 'Cam Profile';
            app.CamProfilePanel.BackgroundColor = [1 1 1];
            app.CamProfilePanel.FontWeight = 'bold';
            app.CamProfilePanel.FontSize = 16;
            app.CamProfilePanel.Position = [690 527 530 337];
            % Create SineConstantCosineAccelerationFunctionDiscriptionsPanel
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel = uipanel(app.UIFigure);
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel.TitlePosition = 'centertop';
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel.Title = 'Sine Constant Cosine Acceleration Function Discriptions';
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel.BackgroundColor = [1 1 1];
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel.FontWeight = 'bold';
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel.FontSize = 16;
            app.SineConstantCosineAccelerationFunctionDiscriptionsPanel.Position = [74 215 461 301];
            % Create TextArea_2
            app.TextArea_2 = uitextarea(app.SineConstantCosineAccelerationFunctionDiscriptionsPanel);
            app.TextArea_2.Position = [1 0 460 275];
            app.TextArea_2.Value = {'1) Constant Acceleration: infinite jerk - not acceptable'; ''; '2) Modified Trapezoid: Low acceleration, rough jerk'; ''; '3) Simple Harmonic: infinite jerk - not acceptable, provides lowest peak acceleration and preasure angle'; ''; '4) Modified Sine: Low velocity, good acceleration'; ''; '5) Cycloydal: Smooth acceleration and jerk - provides zero acceleration at both ends, performs well when coupled to a dwell at each end'; ''; '6) 345 Polynomial: Good compromise to all options'; ''; '7) 4567 Polynomial: Smooth jerk, high acceleration'; ''};
            % Create TextArea_3
            app.TextArea_3 = uitextarea(app.UIFigure);
            app.TextArea_3.HorizontalAlignment = 'center';
            app.TextArea_3.FontAngle = 'italic';
            app.TextArea_3.Position = [510 906 280 38];
            app.TextArea_3.Value = {'Created by Kyle McLaughlin'; 'University of Massachusetts Lowell | Spring 2019'};
            % Create ExportCamProfileButton
            app.ExportCamProfileButton = uibutton(app.UIFigure, 'push');
            app.ExportCamProfileButton.ButtonPushedFcn = createCallbackFcn(app, @ExportCamProfileButtonPushed, true);
            app.ExportCamProfileButton.FontSize = 16;
            app.ExportCamProfileButton.FontWeight = 'bold';
            app.ExportCamProfileButton.Position = [327 21 207 32];
            app.ExportCamProfileButton.Text = 'Export Cam Profile';
            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end
    % App creation and deletion
    methods (Access = public)
        % Construct app
        function app = Double_Dwell_Cam_Calculator
            % Create UIFigure and components
            createComponents(app)
            % Register the app with App Designer
            registerApp(app, app.UIFigure)
            if nargout == 0
                clear app
            end
        end
        % Code that executes before app deletion
        function delete(app)
            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end
0 Comments
Accepted Answer
  Sivani Pentapati
    
 on 2 Nov 2021
        Hi Kyle,
Based on my understanding, you want to export Cam_Displacement variable into a text file. Changing Cam_Displacement to app.Cam_Displacement everywhere in the code except in its declaration resolved the issue. Attaching the updated code for your reference.
You can export matrices using writematrix function where the the path of the output file can be set in the second argument. A temporary workaround to edit function arguments would be copy the code in App Designer into a MATLAB file with the same name as name of the application. This lets you run the app from MATLAB editor. 
More Answers (0)
See Also
Categories
				Find more on Develop uifigure-Based Apps in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
