Advertisement
Hagelberganton

algebralaboration2 gui

Nov 16th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.14 KB | None | 0 0
  1. %Algebralaboration GUI - Anton Hagelberg
  2. clear all; clc; close all;
  3. load('BatMan.mat');
  4. f = figure('rend','painters','pos',[10 10 635 704]);
  5. axis off;
  6.  
  7. %Button creation
  8. c1 = uicontrol(f,'Style','pushbutton','position',[555 75 50 25],...
  9.     'string','Load','Callback',@loadButton_callback);
  10. c2 = uicontrol(f,'Style','pushbutton','position',[555 115 50 26],...
  11.     'String', 'Rotate');
  12. c3 = uicontrol(f,'Style','pushbutton','position',[555 140 50 25],...
  13.     'String', 'Mirror');
  14. c4 = uicontrol(f,'Style','pushbutton','position',[555 170 50 25],...
  15.     'String','Scale');
  16. c5 = uicontrol(f,'Style','pushbutton','position',[545 260 90 25],...
  17.     'String','Scale and rotate','Callback',@scalerot_callback);
  18. c6 = uicontrol(f,'Style','pushbutton','position',[555 330 55 25],...
  19.     'String','Animate');
  20.  
  21. %Textelements
  22. s1 = uicontrol(f,'Style', 'text','position',[410 120 120 15],...
  23.     'String','Degrees to rotate by:');
  24. s2 = uicontrol(f,'Style','text','position',[410 145 120 15],...
  25.     'String','K-value for mirror:');
  26. s3 = uicontrol(f,'Style','text','position',[360 175 140 15],...
  27.     'String','Alpha & Beta multiplicators:');
  28.  
  29. %Textboxcreation
  30. t1 = uicontrol(f,'Style','edit','position',[525 115 30 25]);
  31. t2 = uicontrol(f,'Style','edit','position',[525 140 30 25]);
  32. t3 = uicontrol(f,'Style','edit','position',[530 170 25 25]);
  33. t4 = uicontrol(f,'Style','edit','position',[500 170 25 25]);
  34.  
  35. %Callbacks for textbox-values
  36. set(c2,'Callback',@(src,event)rotation_callback(t1,src,event));
  37. set(c3,'Callback',@(src,event)mirror_callback(t2,src,event));
  38. set(c4,'Callback',@(src,event)scale_callback(t3,t4,src,event));
  39. set(c6,'Callback',@(src,event)animate_callback(src,event));
  40.  
  41. %Load figure
  42. function loadButton_callback(src,event)
  43.     load 'BatMan.mat' X
  44.     subplot(2,2,3);
  45.     PlotFigure(X);
  46. end
  47. %Rotation
  48. function rotation_callback(t1,src,event)
  49.     load 'BatMan.mat' X
  50.     subplot(2,2,1);
  51.     fi = get(t1,'string');
  52.     fi = str2double(fi);
  53.     S = [cosd(fi),-sind(fi);sind(fi),cosd(fi)];
  54.     A = mtimes(S,X);
  55.     PlotFigure(A);
  56. end
  57. %Mirroring
  58. function mirror_callback(t2,src,event)
  59.     load 'BatMan.mat' X
  60.     subplot(2,2,1,'replace');
  61.     k = get(t2,'string');
  62.     k = str2double(k);
  63.     m = 1/(1+k^2);
  64.     S = m.*[1-k^2,2*k;2*k,k^2-1];
  65.     A = mtimes(S,X);
  66.     PlotFigure(A);
  67. end
  68. %Scaling
  69. function scale_callback(t3,t4,src,event)
  70.     load 'BatMan.mat' X
  71.     subplot(2,2,1,'replace');
  72.     alpha = str2double(get(t3,'string'));
  73.     beta = str2double(get(t4,'string'));
  74.     S = [alpha,0;0,beta];
  75.     A = mtimes(S,X);
  76.     PlotFigure(A);
  77. end
  78. %Scaling and rotating
  79. function scalerot_callback(src,event)
  80.     load 'BatMan.mat' X
  81.     subplot(2,2,1,'replace');
  82.     alpha = 2;
  83.     beta = 2;
  84.     fi = 30;
  85.     S2 = [cosd(fi),-sind(fi);sind(fi),cosd(fi)];
  86.     S1 = [alpha,0;0,beta];
  87.     A1 = mtimes(S1,X);
  88.     A2 = mtimes(S2,A1);
  89.     PlotFigure(A2);
  90. end
  91. %Animation
  92. function animate_callback(src,event)
  93.     load 'BatMan.mat' X
  94.     fi = -180:180;
  95.     subplot(2,2,1,'replace');
  96.     for i = fi(1):fi(end)
  97.         S = [cosd(i),-sind(i);sind(i),cosd(i)];
  98.         A = mtimes(S,X);
  99.         PlotFigure(A);
  100.         pause(0.0001);
  101.     end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement