Advertisement
Guest User

Stapfrequenties.m

a guest
Mar 28th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 12.22 KB | None | 0 0
  1. %%              HET WEERGEVEN VAN DE KRITISCHE STAPFREQUENTIES
  2. %%
  3. % -------------------INITIALISATIE VAN HET PROGRAMMA----------------
  4. function varargout = Stapfrequenties(varargin)
  5. % STAPFREQUENTIES M-file for Stapfrequenties.fig
  6. %      STAPFREQUENTIES, by itself, creates a new STAPFREQUENTIES or raises the existing
  7. %      singleton*.
  8. %
  9. %      H = STAPFREQUENTIES returns the handle to a new STAPFREQUENTIES or the handle to
  10. %      the existing singleton*.
  11. %
  12. %      STAPFREQUENTIES('CALLBACK',hObject,eventData,handles,...) calls the local
  13. %      function named CALLBACK in STAPFREQUENTIES.M with the given input arguments.
  14. %
  15. %      STAPFREQUENTIES('Property','Value',...) creates a new STAPFREQUENTIES or raises the
  16. %      existing singleton*.  Starting from the left, property value pairs are
  17. %      applied to the GUI before Stapfrequenties_OpeningFcn gets called.  An
  18. %      unrecognized property name or invalid value makes property application
  19. %      stop.  All inputs are passed to Stapfrequenties_OpeningFcn via varargin.
  20. %
  21. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  22. %      instance to run (singleton)".
  23. %
  24. % See also: GUIDE, GUIDATA, GUIHANDLES
  25.  
  26. % Begin initialization code - DO NOT EDIT
  27. gui_Singleton = 1;
  28. gui_State = struct('gui_Name',       mfilename, ...
  29.                    'gui_Singleton',  gui_Singleton, ...
  30.                    'gui_OpeningFcn', @Stapfrequenties_OpeningFcn, ...
  31.                    'gui_OutputFcn',  @Stapfrequenties_OutputFcn, ...
  32.                    'gui_LayoutFcn',  [] , ...
  33.                    'gui_Callback',   []);
  34. if nargin && ischar(varargin{1})
  35.     gui_State.gui_Callback = str2func(varargin{1});
  36. end
  37.  
  38. if nargout
  39.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  40. else
  41.     gui_mainfcn(gui_State, varargin{:});
  42. end
  43.  
  44.  
  45.  
  46. % -----------FUNCTIES DIE BIJ DE GUI-COMPONENTEN HOREN--------------
  47. function Stapfrequenties_OpeningFcn(hObject, eventdata, handles, varargin)
  48. % Choose default command line output for Stapfrequenties
  49. handles.output = hObject;
  50.  
  51. % Update handles structure
  52. guidata(hObject, handles);
  53. function varargout = Stapfrequenties_OutputFcn(hObject, eventdata, handles)
  54. varargout{1} = handles.output;
  55.  
  56.  
  57. % -------------------ACHTERGRONDKLEUREN AANPASSEN-------------------
  58. function edit_kx_CreateFcn(hObject, eventdata, handles)
  59. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  60.     set(hObject,'BackgroundColor','white');
  61. end
  62. function edit_ky_CreateFcn(hObject, eventdata, handles)
  63. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  64.     set(hObject,'BackgroundColor','white');
  65. end
  66. function edit_lx_CreateFcn(hObject, eventdata, handles)
  67. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  68.     set(hObject,'BackgroundColor','white');
  69. end
  70. function edit_ly_CreateFcn(hObject, eventdata, handles)
  71. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  72.     set(hObject,'BackgroundColor','white');
  73. end
  74. function edit_G_CreateFcn(hObject, eventdata, handles)
  75. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  76.     set(hObject,'BackgroundColor','white');
  77. end
  78. function edit_fsmax_CreateFcn(hObject, eventdata, handles)
  79. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  80.     set(hObject,'BackgroundColor','white');
  81. end
  82. function edit_fsmin_CreateFcn(hObject, eventdata, handles)
  83. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  84.     set(hObject,'BackgroundColor','white');
  85. end
  86.  
  87.  
  88. % ---------------------------CALLBACKS------------------------------
  89. function pb_fj_Callback(hObject, eventdata, handles)
  90. % Deze functie leest de eigenfrequenties in en vult de lijst met eigenfrequenties in:
  91.     [filename, pathname] = uigetfile({'*.txt','All Files (*.*)'});  
  92.     handles.fj =(load(fullfile(pathname,filename)));
  93.     set(handles.cb_fj,'Value',1);
  94.    
  95. %updates the handles structure
  96. guidata(hObject, handles);
  97.    
  98. function pb_phij_Callback(hObject, eventdata, handles)
  99. % Deze functie leest de eigenmodes in:
  100.     [filename, pathname] = uigetfile({'*.txt','All Files (*.*)'});  
  101.     handles.phij =(load(fullfile(pathname,filename)))';
  102.     set(handles.cb_phij,'Value',1);
  103. %updates the handles structure
  104. guidata(hObject, handles);
  105.  
  106. function pb_xij_Callback(hObject, eventdata, handles)
  107. % Deze functie leest de dempingsfactor in:
  108.     [filename, pathname] = uigetfile({'*.txt','All Files (*.*)'});  
  109.     handles.xij =(load(fullfile(pathname,filename)));
  110.     set(handles.cb_xij,'Value',1);
  111. %updates the handles structure
  112. guidata(hObject, handles);
  113.  
  114. function pb_grid_Callback(hObject, eventdata, handles)
  115. % Deze functie leest het grid in:
  116.     [filename, pathname] = uigetfile({'*.txt','All Files (*.*)'});  
  117.     handles.grid =(load(fullfile(pathname,filename)));
  118.     set(handles.cb_grid,'Value',1);
  119. %updates the handles structure
  120. guidata(hObject, handles);
  121.  
  122. function edit_kx_Callback(hObject, eventdata, handles)
  123. % Deze functie leest de kx-coördinaat in.
  124.  
  125.  
  126. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  127. % Daarna wordt ze opgeslaan in 'handles.k'
  128.         input = str2double(get(handles.edit_kx,'String'));
  129.         if isnan(input)
  130.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  131.             uicontrol(hObject)
  132.             return
  133.         else
  134.             handles.kx = str2double(get(hObject,'String'));
  135.         end
  136.    
  137. %updates the handles structure
  138. guidata(hObject, handles);
  139.  
  140. function edit_ky_Callback(hObject, eventdata, handles)
  141. % Deze functie leest de ky-coördinaat in.
  142.  
  143.  
  144. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  145. % Daarna wordt ze opgeslaan in 'handles.k'
  146.         input = str2double(get(handles.edit_ky,'String'));
  147.         if isnan(input)
  148.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  149.             uicontrol(hObject)
  150.             return
  151.         else
  152.             handles.ky = str2double(get(hObject,'String'));
  153.         end
  154.    
  155. %updates the handles structure
  156. guidata(hObject, handles);
  157.  
  158. function edit_lx_Callback(hObject, eventdata, handles)
  159. % Deze functie leest de lx-coördinaat in.
  160.  
  161.  
  162. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  163. % Daarna wordt ze opgeslaan in 'handles.l'
  164.         input = str2double(get(handles.edit_lx,'String'));
  165.         if isnan(input)
  166.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  167.             uicontrol(hObject)
  168.             return
  169.         else
  170.             handles.lx = str2double(get(hObject,'String'));
  171.         end
  172.    
  173. %updates the handles structure
  174. guidata(hObject, handles);
  175.  
  176. function edit_ly_Callback(hObject, eventdata, handles)
  177. % Deze functie leest de ly-coördinaat in.
  178.  
  179.  
  180. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  181. % Daarna wordt ze opgeslaan in 'handles.l'
  182.         input = str2double(get(handles.edit_ly,'String'));
  183.         if isnan(input)
  184.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  185.             uicontrol(hObject)
  186.             return
  187.         else
  188.             handles.ly = str2double(get(hObject,'String'));
  189.         end
  190.    
  191. %updates the handles structure
  192. guidata(hObject, handles);
  193.  
  194. function edit_G_Callback(hObject, eventdata, handles)
  195. % Deze functie leest het gewicht in van de voetganger.
  196.  
  197.  
  198. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  199. % Ook wordt gecontroleerd of de waarde positief is, daarna wordt ze
  200. % opgeslaan in 'handles.G'
  201.         input = str2double(get(handles.edit_G,'String'));
  202.         if isnan(input)
  203.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  204.             uicontrol(hObject)
  205.             return
  206.         elseif (input <= 0)
  207.             msgbox('Geef een positief gewicht in','Foutmelding!', 'error');
  208.             set(handles.edit_G,'String','');
  209.             else
  210.             handles.G = str2double(get(hObject,'String'));
  211.         end
  212.    
  213. %updates the handles structure
  214. guidata(hObject, handles);
  215.  
  216. function edit_fsmin_Callback(hObject, eventdata, handles)
  217. % Deze functie leest de min fs waarde in.
  218.  
  219.  
  220. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  221. % Ook wordt gecontroleerd of de waarde positief is, daarna wordt ze
  222. % opgeslaan in 'handles.fsmin'
  223.         input = str2double(get(handles.edit_fsmin,'String'));
  224.         if isnan(input)
  225.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  226.             uicontrol(hObject)
  227.             return
  228.         elseif (input <= 0)
  229.             msgbox('Geef een positief gewicht in','Foutmelding!', 'error');
  230.             set(handles.edit_fsmin,'String','');
  231.             else
  232.             handles.fsmin = str2double(get(hObject,'String'));
  233.         end
  234.    
  235. %updates the handles structure
  236. guidata(hObject, handles);
  237.  
  238. function edit_fsmax_Callback(hObject, eventdata, handles)
  239. % Deze functie leest de max fs waarde in.
  240.  
  241.  
  242. % Eerst wordt er gecontroleerd of er een numerieke waarde ingegeven is.
  243. % Ook wordt gecontroleerd of de waarde positief is, daarna wordt ze
  244. % opgeslaan in 'handles.fsmin'
  245.         input = str2double(get(handles.edit_fsmax,'String'));
  246.         if isnan(input)
  247.             errordlg('Je moet een numerieke waarde ingeven','Bad Input','modal')
  248.             uicontrol(hObject)
  249.             return
  250.         elseif (input <= 0)
  251.             msgbox('Geef een positief gewicht in','Foutmelding!', 'error');
  252.             set(handles.edit_fsmax,'String','');
  253.             else
  254.             handles.fsmax = str2double(get(hObject,'String'));
  255.         end
  256.    
  257. %updates the handles structure
  258. guidata(hObject, handles);
  259.  
  260. function pb_plotapart_Callback(hObject, eventdata, handles)
  261. % Deze functie plot de maximale waarden op een aparte figuur.
  262.  
  263. copyfig=copyobj(handles.grafiek,figure(1));
  264. set(copyfig, 'Units', 'normalized', 'Position', [.1 .1 .8 .8]);
  265. xlabel('Stapfrequenties [Hz]');
  266. ylabel('Versnelling[m/s²]');
  267. title('Versnelling ten gevolge van de verschillende stapfrequenties voor Young laagfrequent');
  268.  
  269. function pb_bereken_Callback(hObject, eventdata, handles)
  270.  
  271. t=0;
  272.  
  273. % We gaan op zoek naar het dichtsgelegen gridpunt
  274. distances=zeros(length(handles.phij(1,:)),2);
  275. for a=1:length(handles.phij(1,:))
  276.     distances(a,1)=sqrt(abs(handles.kx - handles.grid(a,2))^2 + abs(handles.ky - handles.grid(a,3))^2);
  277.     distances(a,2)=sqrt(abs(handles.lx - handles.grid(a,2))^2 + abs(handles.ly - handles.grid(a,3))^2);
  278. end
  279.     [~,handles.k]=min((distances(:,1)));
  280.     [~,handles.l]=min((distances(:,2)));
  281.  
  282. urms=zeros(1,(handles.fsmax-handles.fsmin)/0.05+1);
  283. u=zeros(1,4);
  284. j=length(handles.fj);
  285.  
  286.  
  287. while handles.fj(j)>15
  288.     handles.fj(j)=[];
  289.     handles.xij(j)=[];
  290.     handles.phij(j,:)=[];
  291.     j=j-1;
  292. end
  293.            
  294. for fs=handles.fsmin:0.01:handles.fsmax;
  295.  t=t+1;  
  296.            
  297.     for h=1:4
  298.             fh=h*fs;
  299.             switch h
  300.                 case 1
  301.                     alpha=min(0.37*(fh-0.95),0.5);
  302.                 case 2
  303.                     alpha=0.0044*(fh+12.3);
  304.                 case 3
  305.                     alpha=0.005*(fh+5.2);
  306.                 case 4
  307.                     alpha=0.0051*(fh+2);
  308.             end
  309.             Fh=alpha*handles.G;
  310.             beta=(fh./handles.fj);
  311.             u(h)=sum(abs((-beta.^2.*handles.phij(:,handles.k).*handles.phij(:,handles.l))./((1-beta.^2)+2.*handles.xij.*beta.*i)))*Fh;
  312.     end
  313.  
  314.     urms(t)=sqrt(u(1)^2+u(2)^2+u(3)^2+u(4)^2)/sqrt(2);
  315. end
  316.  
  317. if any(urms)==0
  318.     set(handles.txt_message,'String','Opgelet! Het input of outputpunt bevindt zich op de rand van de plaat');
  319. else
  320.     set(handles.txt_message,'String','');
  321. end
  322.  
  323. fs=handles.fsmin:0.01:handles.fsmax;
  324. plot(fs,urms);
  325. xlabel('Stapfrequenties [Hz]');
  326. ylabel('Versnelling[m/s²]');
  327. title('Versnelling ten gevolge van de verschillende stapfrequenties voor Young laagfrequent');
  328.  
  329.  
  330. % --------------------------------------------------------------------
  331. function Bestand_Callback(hObject, eventdata, handles)
  332.  
  333. function Nieuw_Callback(hObject, eventdata, handles)
  334. % Deze functie roept Reset.m aan die het programma afsluit
  335. % en opnieuw opstart.
  336. run(strcat(pwd,'\Reset.m'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement