Hi everybody, i was working on a Airfoil generator: Airfoil generation using CST parameterization method i wanted to make an GUI of it, but not having any result, no plotting. can anyone at least let me know where is the problem.
function varargout = CST(varargin)% CST MATLAB code for CST.fig
% CST, by itself, creates a new CST or raises the existing
% singleton*.
%
% H = CST returns the handle to a new CST or the handle to
% the existing singleton*.
%% CST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CST.M with the given input arguments.
%% CST('Property','Value',...) creates a new CST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before CST_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to CST_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 CST
% Last Modified by GUIDE v2.5 14-Aug-2016 17:32:10
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @CST_OpeningFcn, ... 'gui_OutputFcn', @CST_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 CST is made visible.
function CST_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 CST (see VARARGIN)
% Choose default command line output for CST
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes CST wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = CST_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 a_Callback(hObject, eventdata, handles)% hObject handle to a (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 a as text
% str2double(get(hObject,'String')) returns contents of a as a double
% --- Executes during object creation, after setting all properties.
function a_CreateFcn(hObject, eventdata, handles)% hObject handle to a (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');endfunction d_Callback(hObject, eventdata, handles)% hObject handle to d (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 d as text
% str2double(get(hObject,'String')) returns contents of d as a double
% --- Executes during object creation, after setting all properties.function d_CreateFcn(hObject, eventdata, handles)% hObject handle to d (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');endfunction N_Callback(hObject, eventdata, handles)% hObject handle to N (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 N as text
% str2double(get(hObject,'String')) returns contents of N as a double
% --- Executes during object creation, after setting all properties.function N_CreateFcn(hObject, eventdata, handles)% hObject handle to N (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');endfunction dz_Callback(hObject, eventdata, handles)% hObject handle to dz (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 dz as text
% str2double(get(hObject,'String')) returns contents of dz as a double
% --- Executes during object creation, after setting all properties.function dz_CreateFcn(hObject, eventdata, handles)% hObject handle to dz (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');endfunction b_Callback(hObject, eventdata, handles)% hObject handle to b (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 b as text
% str2double(get(hObject,'String')) returns contents of b as a double
% --- Executes during object creation, after setting all properties.function b_CreateFcn(hObject, eventdata, handles)% hObject handle to b (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');endfunction c_Callback(hObject, eventdata, handles)% hObject handle to c (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 c as text
% str2double(get(hObject,'String')) returns contents of c as a double
% --- Executes during object creation, after setting all properties.function c_CreateFcn(hObject, eventdata, handles)% hObject handle to c (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');endfunction e_Callback(hObject, eventdata, handles)% hObject handle to e (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 e as text
% str2double(get(hObject,'String')) returns contents of e as a double
% --- Executes during object creation, after setting all properties.function e_CreateFcn(hObject, eventdata, handles)% hObject handle to e (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');endfunction f_Callback(hObject, eventdata, handles)% hObject handle to f (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 f as text
% str2double(get(hObject,'String')) returns contents of f as a double
% --- Executes during object creation, after setting all properties.function f_CreateFcn(hObject, eventdata, handles)% hObject handle to f (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)a = str2num(get(handles.a, 'string'));b = str2num(get(handles.b, 'string'));c = str2num(get(handles.c, 'string'));d = str2num(get(handles.d, 'string'));e = str2num(get(handles.e, 'string'));f = str2num(get(handles.f, 'string'));dz = str2num(get(handles.dz, 'string'));N = str2num(get(handles.N, 'string'));wl = [a , b , c];wu = [d , e , f];%function [coord] =CST_airfoil(wl,wu,dz,N);
% Description : Create a set of airfoil coordinates using CST parametrization method
% Input : wl = CST weight of lower surface
% wu = CST weight of upper surface
% dz = trailing edge thickness
% Output : coord = set of x-y coordinates of airfoil generated by CST
% Create x coordinate
x=ones(N+1,1);y=zeros(N+1,1);zeta=zeros(N+1,1);for i=1:N+1 zeta(i)=2*pi/N*(i-1); x(i)=0.5*(cos(zeta(i))+1);end% N1 and N2 parameters (N1 = 0.5 and N2 = 1 for airfoil shape)
N1 = 0.5;N2 = 1;zerind = find(x(:,1) == 0); % Used to separate upper and lower surfaces
xl= x(1:zerind-1); % Lower surface x-coordinates
xu = x(zerind:end); % Upper surface x-coordinates
[yl] = ClassShape(wl,xl,N1,N2,-dz); % Call ClassShape function to determine lower surface y-coordinates
[yu] = ClassShape(wu,xu,N1,N2,dz); % Call ClassShape function to determine upper surface y-coordinates
y = [yl;yu]; % Combine upper and lower y coordinates
coord = [x y]; % Combine x and y into single output
%%Function to calculate class and shape function
function [y] = ClassShape(w,x,N1,N2,dz);% Class function; taking input of N1 and N2
for i = 1:size(x,1) C(i,1) = x(i)^N1*((1-x(i))^N2);end% Shape function; using Bernstein Polynomials
n = size(w,2)-1; % Order of Bernstein polynomials
for i = 1:n+1 K(i) = factorial(n)/(factorial(i-1)*(factorial((n)-(i-1))));endfor i = 1:size(x,1) S(i,1) = 0; for j = 1:n+1 S(i,1) = S(i,1) + w(j)*K(j)*x(i)^(j-1)*((1-x(i))^(n-(j-1))); endend% Calculate y output
for i = 1:size(x,1) y(i,1) = C(i,1)*S(i,1) + x(i)*dz;endaxes(handles.axes1);plot(x,y);
Best Answer