Facebook
From papillon, 6 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 192
  1. 1. Dvije matrice: sabiranje,oduzimanje,mnozenje,dijeljenje,transponovanje,inverzna.
  2. % Size changed function: UlaznipodaciPanel
  3.         function UlaznipodaciPanelSizeChanged(app, event)
  4.             position = app.UlaznipodaciPanel.Position;
  5.            
  6.         end
  7.  
  8. % Value changed function: ElementiprvematriceTextArea
  9.         function ElementiprvematriceTextAreaValueChanged(app, event)
  10.             value = app.ElementiprvematriceTextArea.Value;
  11.            
  12.         end
  13.  
  14. % Button pushed function: IspisirezultateButton
  15.         function IspisirezultateButtonPushed(app, event)
  16.             mat1 = str2num(char(app.ElementiprvematriceTextArea.Value));
  17.             mat2 = str2num(char(app.ElementidrugematriceTextArea.Value));
  18.             %prikaz matrica
  19.             app.PrvamatricaTextArea.Value = mat2str(mat1);
  20.             app.DrugamatricaTextArea.Value = mat2str(mat2);
  21.              % Racunanje i prikaz inverznih matrica
  22.             if det(mat1) ~= 0
  23.                 app.InverznamatricaTextArea.Value = mat2str(inv(mat1));
  24.             else
  25.                 app.InverznamatricaTextArea.Value = 'N/A';
  26.             end
  27.  
  28.             if det(mat2) ~= 0
  29.                 app.InverznamatricaTextArea_2.Value = mat2str(inv(mat2));
  30.             else
  31.                 app.InverznamatricaTextArea_2.Value = 'N/A';
  32.             end
  33.              % Prikaz transponovanih matrica
  34.             app.TransponovanamatricaTextArea.Value = mat2str(mat1');
  35.             app.TransponovanamatricaTextArea_2.Value = mat2str(mat2');
  36.             % Operacije sa matricama
  37.             if isequal(size(mat1), size(mat2))
  38.                 app.ZbirmatricaTextArea.Value = mat2str(mat1 + mat2);
  39.                 app.RazlikamatricaTextArea.Value = mat2str(mat1 - mat2);
  40.             else
  41.                 app.ZbirmatricaTextArea.Value = 'N/A';
  42.                 app.RazlikamatricaTextArea.Value = 'N/A';
  43.             end
  44.  
  45.             if size(mat1, 2) == size(mat2, 1)
  46.                 app.ProizvodmatricaTextArea.Value = mat2str(mat1 * mat2);
  47.             else
  48.                 app.ProizvodmatricaTextArea.Value = 'N/A';
  49.             end
  50.    
  51.  
  52.         end
  53.     end
  54.    
  55.    
  56.  2. Jedna matrica: dijagonalna,inverzna,gornjat i donjat
  57. % Button pushed function: DijagonalnaMatricaButton
  58.         function DijagonalnaMatricaButtonPushed(app, event)
  59.     matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
  60.     matrix = str2num(matrixStr); % Convert char to numerical array
  61.     if isempty(matrix)
  62.         app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
  63.         return;
  64.     end
  65.     diag_matrix = diag(diag(matrix));
  66.     app.IspisrezultataTextArea.Value = mat2str(diag_matrix);
  67.         end
  68.  
  69. % Button pushed function: InverznaButton
  70.         function InverznaButtonPushed(app, event)
  71.     matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
  72.     matrix = str2num(matrixStr); % Convert char to numerical array
  73.     if isempty(matrix)
  74.         app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
  75.         return;
  76.     end
  77.     if det(matrix) == 0
  78.         app.IspisrezultataTextArea.Value = 'Matrica nema inverznu!';
  79.         return;
  80.     end
  81.     inv_matrix = inv(matrix);
  82.     app.IspisrezultataTextArea.Value = mat2str(inv_matrix);
  83.         end
  84.  
  85.  
  86.         % Button pushed function: GornjetrougaonaButton
  87.         function GornjetrougaonaButtonPushed(app, event)
  88.     matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
  89.     matrix = str2num(matrixStr); % Convert char to numerical array
  90.     if isempty(matrix)
  91.         app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
  92.         return;
  93.     end
  94.     upper_tri = triu(matrix);
  95.     app.IspisrezultataTextArea.Value = mat2str(upper_tri);
  96.  
  97.         end
  98.  
  99.         % Button pushed function: DonjetrougaonaButton
  100.         function DonjetrougaonaButtonPushed(app, event)
  101.     matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
  102.     matrix = str2num(matrixStr); % Convert char to numerical array
  103.     if isempty(matrix)
  104.         app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
  105.         return;
  106.     end
  107.     lower_tri = tril(matrix);
  108.     app.IspisrezultataTextArea.Value = mat2str(lower_tri);
  109.         end
  110.     end
  111.  
  112.  
  113. 3. Sve o recenicama
  114. % Button pushed function: StartButton
  115.         function StartButtonPushed(app, event)
  116.               % Get input text
  117.             text = app.InputTextArea.Value;
  118.             text = string(text);
  119.             % Count words
  120.            
  121.             words = strsplit(text);
  122.             numWords = length(words);
  123.  
  124.            
  125.             % Count exclamation sentences
  126.             numExclSentences = numel(strfind(text, '!'));
  127.             numPeriodSentences = numel(strfind(text, '.'));
  128.             numQuestionSentences = numel(strfind(text, '?'));
  129.             numSentences = numExclSentences + numPeriodSentences + numQuestionSentences;
  130.             % Count vowels
  131.             textlower = lower(text);
  132.             numa = numel(strfind(textlower, 'a'));
  133.             nume = numel(strfind(textlower, 'e'));
  134.             numi = numel(strfind(textlower, 'i'));
  135.             numo = numel(strfind(textlower, 'o'));
  136.             numu = numel(strfind(textlower, 'u'));
  137.  
  138.             numVowels = numa+nume+numi+numo+numu;
  139.  
  140.  
  141.  
  142.             % Count non-vowels
  143.             numNonVowels = sum(isletter(text)) - numVowels;  % Count all letters minus vowels
  144.  
  145.             % Update fields
  146.             app.WordsEditField.Value = num2str(numWords);
  147.             app.SentencesEditField.Value = num2str(numSentences);
  148.             app.ExclSentencesEditField.Value = num2str(numExclSentences);
  149.             app.PeriodSentencesEditField.Value = num2str(numPeriodSentences);
  150.             app.QuestionSentencesEditField.Value = num2str(numQuestionSentences);
  151.             app.VowelsEditField.Value = num2str(numVowels);
  152.             app.NonVowelsEditField.Value = num2str(numNonVowels);
  153.  
  154.  
  155.         end
  156.  
  157.         % Button pushed function: DeleteButton
  158.         function DeleteButtonPushed(app, event)
  159.             app.InputTextArea.Value = '';
  160.            
  161.             % Clear the results fields
  162.             app.WordsEditField.Value = num2str(0);
  163.             app.SentencesEditField.Value = num2str(0);
  164.             app.ExclSentencesEditField.Value =num2str(0);
  165.             app.PeriodSentencesEditField.Value =num2str(0);
  166.             app.QuestionSentencesEditField.Value = num2str(0);
  167.             app.VowelsEditField.Value = num2str(0);
  168.             app.NonVowelsEditField.Value = num2str(0);
  169.      
  170.         end
  171.     end
  172.  
  173.  
  174. 4. Spajanje rijeci,slova,suglasnici..
  175. % Button pushed function: SpajanjeRijeciButton
  176.         function SpajanjeRijeciButtonPushed(app, event)
  177.         % Uzmi tekst iz EditField
  178.         sentence = app.EditField.Value;
  179.        
  180.         % Razdvoji riječi po razmacima (ili drugim separatorima ako su uneseni)
  181.         words = strsplit(sentence);  % Razdvaja riječi po razmacima
  182.        
  183.         mergedSentence = strjoin(words, '');  % Spaja riječi razmakom
  184.        
  185.         % Postavi spojeni tekst u ResultTextArea
  186.         app.ResultTextArea.Value = mergedSentence;
  187.         end
  188.  
  189.         % Button pushed function: SlovaiSuglasniciButton
  190.         function SlovaiSuglasniciButtonPushed(app, event)
  191.             sentence = app.EditField.Value;
  192.             vowels = 'aeiouAEIOU';
  193.             numVowels = sum(ismember(sentence, vowels));
  194.             numNonVowels = sum(~ismember(sentence, vowels) & isletter(sentence));
  195.             app.ResultTextArea.Value = sprintf('Broj slova: %d\nBroj suglasnika: %d\n', numVowels + numNonVowels, numNonVowels);
  196.         end
  197.  
  198.         % Button pushed function:
  199.         % BrojRecenicaBrojRijeciBrojSuglasnikaButton
  200.         function BrojRecenicaBrojRijeciBrojSuglasnikaButtonPushed(app, event)
  201.             sentence = app.EditField.Value;
  202.             words = strsplit(sentence);
  203.             result = '';
  204.             vowels = 'aeiouAEIOU';
  205.            
  206.             for i = 1:length(words)
  207.                 word = words{i};
  208.                 numVowels = sum(ismember(word, vowels));
  209.                 result = [result, sprintf('Riječ: %s\n Broj slova: %d\n Broj samoglasnika: %d\n Samoglasnici: %s\n', ...
  210.                     word, length(word), numVowels, word(ismember(word, vowels)))];
  211.             end
  212.            
  213.             app.ResultTextArea.Value = result;
  214.         end
  215.     end
  216.  
  217.  
  218. 5. Funckija sa omegom
  219. % Button pushed function: PrikaziButton
  220.         function PrikaziButtonPushed(app, event)
  221.             % Get parameter values from GUI
  222.             T = app.TEditField.Value;
  223.             omega = app.OmegaEditField.Value;
  224.             phi = app.PhiEditField.Value;
  225.             t_min = app.TminEditField.Value;
  226.             t_max = app.TmaxEditField.Value;
  227.  
  228.             % Generate time vector
  229.             t = linspace(t_min, t_max, 100);
  230.  
  231.             % Calculate function f(t)
  232.             f = exp(-t/T) .* sin(omega*t + phi);
  233.  
  234.             % Plot the function
  235.             plot(app.UIAxes, t, f);
  236.             xlabel(app.UIAxes, 't');
  237.             ylabel(app.UIAxes, 'f(t)');
  238.             title(app.UIAxes, 'Prikaz funkcije');
  239.         end
  240.     end
  241.  
  242.  
  243. 6. Smajlic
  244. % Button pushed function: SretniButton
  245.         function SretniButtonPushed(app, event)
  246. % Kreiranje koordinata za smajlića
  247.     t = 0:pi/50:2*pi;
  248.     x_head = 4 * cos(t);
  249.     y_head = 4 * sin(t);
  250.    
  251.     x_eye1 = cos(t) - 2;
  252.     y_eye1 = sin(t) + 1.5;
  253.    
  254.     x_eye2 = cos(t) + 2;
  255.     y_eye2 = sin(t) + 1.5;
  256.    
  257.     t_mouth = pi:pi/50:2*pi;
  258.     x_mouth = 3 * cos(t_mouth);
  259.     y_mouth = 3 * sin(t_mouth);
  260.    
  261.         % Prikazivanje smajlića na UIAxes komponenti
  262.     plot(app.UIAxes, x_head, y_head, 'LineWidth', 2, 'Color', 'yellow');
  263.     hold(app.UIAxes, 'on');  % Drži trenutni grafikon
  264.    
  265.     plot(app.UIAxes, x_eye1, y_eye1, 'LineWidth', 2, 'Color', 'black');
  266.     plot(app.UIAxes, x_eye2, y_eye2, 'LineWidth', 2, 'Color', 'black');
  267.     plot(app.UIAxes, x_mouth, y_mouth, 'LineWidth', 2, 'Color', 'black');
  268.    
  269.     hold(app.UIAxes, 'off');  % Završi držanje grafikona
  270.  
  271.         end
  272.  
  273.         % Button pushed function: TuzniButton
  274.         function TuzniButtonPushed(app, event)
  275. % Kreiranje koordinata za tužnog smajlića
  276. t = 0:pi/50:2*pi;
  277.     x = 4 * cos(t);
  278.     y = 4 * sin(t);
  279.    
  280.     t1 = 0:pi/50:2*pi;
  281.     x1 = cos(t1) - 2;
  282.     y1 = sin(t1) + 1.5;
  283.    
  284.     t2 = 0:pi/50:2*pi;
  285.     x2 = cos(t2) + 2;
  286.     y2 = sin(t2) + 1.5;
  287.    
  288.     t3 = pi:pi/50:2*pi;
  289.     x3 = 3 * cos(t3);
  290.     y3 = -3 * sin(t3) - 2.3;
  291.    
  292.        % Prikazivanje tužnog smajlića na UIAxes komponenti
  293.     plot(app.UIAxes, x, y, 'LineWidth', 2, 'Color', 'yellow');
  294.     hold(app.UIAxes, 'on');  % Drži trenutni grafikon
  295.    
  296.     plot(app.UIAxes, x1, y1, 'LineWidth', 2, 'Color', 'black');
  297.     plot(app.UIAxes, x2, y2, 'LineWidth', 2, 'Color', 'black');
  298.     plot(app.UIAxes, x3, y3, 'LineWidth', 2, 'Color', 'black');
  299.    
  300.     hold(app.UIAxes, 'off');  % Završi držanje grafikona
  301.         end
  302.     end
  303.  
  304.  
  305. 7. Zastava mijenja boju
  306. % Button pushed function: PromijeniBojuButton
  307.         function PromijeniBojuButtonPushed(app, event)
  308. % Clear previous plot
  309.     cla(app.UIAxes);
  310.  
  311.     % Generate random color for the flag
  312.     color = rand(1, 3); % Random RGB color
  313.  
  314.     % Generate data
  315.     t = 0:0.1:4*pi;
  316.     y1 = 1/2*sin(t) - 1;
  317.     y2 = 1/2*sin(t) + 1;
  318.  
  319.     % Plot on UIAxes
  320.     hold(app.UIAxes, 'on');
  321.     area(app.UIAxes, t, y2, 'FaceColor', color, 'EdgeColor', color);
  322.     area(app.UIAxes, t, y1, 'FaceColor', color, 'EdgeColor', color);
  323.     hold(app.UIAxes, 'off');
  324.  
  325.     % Set axes properties
  326.     xlabel(app.UIAxes, 'X osa');
  327.     ylabel(app.UIAxes, 'Y osa');
  328.     title(app.UIAxes, 'Grafikon na UI Axes');
  329.     axis(app.UIAxes, [-2 15 -2 2]); % Set axis limits
  330.         end
  331.     end
  332.  
  333.  
  334. 8. GUI sa matricom A, treba izaci B
  335. % Button pushed function: IzracunajButton
  336.         function IzracunajButtonPushed(app, event)
  337.             A_str = app.ElementiMatriceATextArea.Value;
  338.  
  339. % Split the input string into lines
  340. lines = splitlines(A_str);
  341.  
  342. % Initialize matrix A
  343. A = [];
  344.  
  345. % Iterate through each line and convert to numbers
  346. for i = 1:numel(lines)
  347.     line = strtrim(lines{i}); % Remove leading/trailing whitespace
  348.     if ~isempty(line)
  349.         row = str2double(strsplit(line)); % Convert line to numbers
  350.         A = [A; row]; % Append row to matrix A
  351.     end
  352. end
  353.  
  354. % Check if A is empty or not a valid matrix
  355. if isempty(A) || any(isnan(A(:)))
  356.     % Display error if input is not a valid matrix
  357.     app.OutputTextArea.Value = 'Error: Invalid matrix input.';
  358.     return;
  359. end
  360.  
  361.  
  362.     % Calculate matrix B
  363.     % a) Exclude the last column of A
  364.     B_a = A(:, 1:end-1);
  365.  
  366.     % b) Exclude the first row of A
  367.     B_b = A(2:end, :);
  368.  
  369.     % c) Change signs of elements in the intersection of last row and first column
  370.     A(end, 1) = -A(end, 1);
  371.     B_c = A;
  372.  
  373.     % Display matrix B in OutputTextArea
  374.     app.ElementiMatriceBTextArea.Value = sprintf(['B (iskljucenje zadnje kolone):\n%s\n\nB (iskljucenje prvog reda):\n%s\n\nB (presjek' ...
  375.         '):\n%s'], ...
  376.         mat2str(B_a), mat2str(B_b), mat2str(B_c));
  377.         end
  378.     end
  379.  
  380.  
  381. 9. Trostrana piramida:
  382. % Button pushed function: PrikazipiramiduButton
  383.         function PrikazipiramiduButtonPushed(app, event)
  384.          height = app.VisinaPiramideEditField.Value;
  385.         baseLength = app.DuzinaOsnoviceEditField.Value;
  386.  
  387.         % Calculate the vertices of the tetrahedron
  388.         A = [0, 0, 0];
  389.         B = [baseLength, 0, 0];
  390.         C = [baseLength/2, baseLength*sqrt(3)/2, 0];
  391.         D = [baseLength/2, baseLength*sqrt(3)/6, height];
  392.  
  393.         % Define the faces of the tetrahedron
  394.         faces = [
  395.             1, 2, 3;
  396.             1, 3, 4;
  397.             1, 4, 2;
  398.             2, 3, 4
  399.         ];
  400.  
  401.         % Plot the tetrahedron
  402.         cla(app.UIAxes); % Clear previous plot
  403.         hold(app.UIAxes, 'on');
  404.         patch(app.UIAxes, 'Vertices', [A; B; C; D], 'Faces', faces, 'FaceColor', 'magenta', 'EdgeColor', 'k');
  405.         view(app.UIAxes, 3); % Set 3D view
  406.         axis(app.UIAxes, 'equal'); % Set equal axis scales
  407.         xlabel(app.UIAxes, 'X');
  408.         ylabel(app.UIAxes, 'Y');
  409.         zlabel(app.UIAxes, 'Z');
  410.         title(app.UIAxes, 'Tetrahedron');
  411.         hold(app.UIAxes, 'off');
  412.         end
  413.     end
  414.  
  415.  
  416.