- 1. Dvije matrice: sabiranje,oduzimanje,mnozenje,dijeljenje,transponovanje,inverzna.
- % Size changed function: UlaznipodaciPanel
- function UlaznipodaciPanelSizeChanged(app, event)
- position = app.UlaznipodaciPanel.Position;
- end
- % Value changed function: ElementiprvematriceTextArea
- function ElementiprvematriceTextAreaValueChanged(app, event)
- value = app.ElementiprvematriceTextArea.Value;
- end
- % Button pushed function: IspisirezultateButton
- function IspisirezultateButtonPushed(app, event)
- mat1 = str2num(char(app.ElementiprvematriceTextArea.Value));
- mat2 = str2num(char(app.ElementidrugematriceTextArea.Value));
- %prikaz matrica
- app.PrvamatricaTextArea.Value = mat2str(mat1);
- app.DrugamatricaTextArea.Value = mat2str(mat2);
- % Racunanje i prikaz inverznih matrica
- if det(mat1) ~= 0
- app.InverznamatricaTextArea.Value = mat2str(inv(mat1));
- else
- app.InverznamatricaTextArea.Value = 'N/A';
- end
- if det(mat2) ~= 0
- app.InverznamatricaTextArea_2.Value = mat2str(inv(mat2));
- else
- app.InverznamatricaTextArea_2.Value = 'N/A';
- end
- % Prikaz transponovanih matrica
- app.TransponovanamatricaTextArea.Value = mat2str(mat1');
- app.TransponovanamatricaTextArea_2.Value = mat2str(mat2');
- % Operacije sa matricama
- if isequal(size(mat1), size(mat2))
- app.ZbirmatricaTextArea.Value = mat2str(mat1 + mat2);
- app.RazlikamatricaTextArea.Value = mat2str(mat1 - mat2);
- else
- app.ZbirmatricaTextArea.Value = 'N/A';
- app.RazlikamatricaTextArea.Value = 'N/A';
- end
- if size(mat1, 2) == size(mat2, 1)
- app.ProizvodmatricaTextArea.Value = mat2str(mat1 * mat2);
- else
- app.ProizvodmatricaTextArea.Value = 'N/A';
- end
- end
- end
- 2. Jedna matrica: dijagonalna,inverzna,gornjat i donjat
- % Button pushed function: DijagonalnaMatricaButton
- function DijagonalnaMatricaButtonPushed(app, event)
- matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
- matrix = str2num(matrixStr); % Convert char to numerical array
- if isempty(matrix)
- app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
- return;
- end
- diag_matrix = diag(diag(matrix));
- app.IspisrezultataTextArea.Value = mat2str(diag_matrix);
- end
- % Button pushed function: InverznaButton
- function InverznaButtonPushed(app, event)
- matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
- matrix = str2num(matrixStr); % Convert char to numerical array
- if isempty(matrix)
- app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
- return;
- end
- if det(matrix) == 0
- app.IspisrezultataTextArea.Value = 'Matrica nema inverznu!';
- return;
- end
- inv_matrix = inv(matrix);
- app.IspisrezultataTextArea.Value = mat2str(inv_matrix);
- end
- % Button pushed function: GornjetrougaonaButton
- function GornjetrougaonaButtonPushed(app, event)
- matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
- matrix = str2num(matrixStr); % Convert char to numerical array
- if isempty(matrix)
- app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
- return;
- end
- upper_tri = triu(matrix);
- app.IspisrezultataTextArea.Value = mat2str(upper_tri);
- end
- % Button pushed function: DonjetrougaonaButton
- function DonjetrougaonaButtonPushed(app, event)
- matrixStr = char(app.UnesielementematriceTextArea.Value); % Convert to char
- matrix = str2num(matrixStr); % Convert char to numerical array
- if isempty(matrix)
- app.IspisrezultataTextArea.Value = 'Unesite validnu matricu!';
- return;
- end
- lower_tri = tril(matrix);
- app.IspisrezultataTextArea.Value = mat2str(lower_tri);
- end
- end
- 3. Sve o recenicama
- % Button pushed function: StartButton
- function StartButtonPushed(app, event)
- % Get input text
- text = app.InputTextArea.Value;
- text = string(text);
- % Count words
- words = strsplit(text);
- numWords = length(words);
- % Count exclamation sentences
- numExclSentences = numel(strfind(text, '!'));
- numPeriodSentences = numel(strfind(text, '.'));
- numQuestionSentences = numel(strfind(text, '?'));
- numSentences = numExclSentences + numPeriodSentences + numQuestionSentences;
- % Count vowels
- textlower = lower(text);
- numa = numel(strfind(textlower, 'a'));
- nume = numel(strfind(textlower, 'e'));
- numi = numel(strfind(textlower, 'i'));
- numo = numel(strfind(textlower, 'o'));
- numu = numel(strfind(textlower, 'u'));
- numVowels = numa+nume+numi+numo+numu;
- % Count non-vowels
- numNonVowels = sum(isletter(text)) - numVowels; % Count all letters minus vowels
- % Update fields
- app.WordsEditField.Value = num2str(numWords);
- app.SentencesEditField.Value = num2str(numSentences);
- app.ExclSentencesEditField.Value = num2str(numExclSentences);
- app.PeriodSentencesEditField.Value = num2str(numPeriodSentences);
- app.QuestionSentencesEditField.Value = num2str(numQuestionSentences);
- app.VowelsEditField.Value = num2str(numVowels);
- app.NonVowelsEditField.Value = num2str(numNonVowels);
- end
- % Button pushed function: DeleteButton
- function DeleteButtonPushed(app, event)
- app.InputTextArea.Value = '';
- % Clear the results fields
- app.WordsEditField.Value = num2str(0);
- app.SentencesEditField.Value = num2str(0);
- app.ExclSentencesEditField.Value =num2str(0);
- app.PeriodSentencesEditField.Value =num2str(0);
- app.QuestionSentencesEditField.Value = num2str(0);
- app.VowelsEditField.Value = num2str(0);
- app.NonVowelsEditField.Value = num2str(0);
- end
- end
- 4. Spajanje rijeci,slova,suglasnici..
- % Button pushed function: SpajanjeRijeciButton
- function SpajanjeRijeciButtonPushed(app, event)
- % Uzmi tekst iz EditField
- sentence = app.EditField.Value;
- % Razdvoji riječi po razmacima (ili drugim separatorima ako su uneseni)
- words = strsplit(sentence); % Razdvaja riječi po razmacima
- mergedSentence = strjoin(words, ''); % Spaja riječi razmakom
- % Postavi spojeni tekst u ResultTextArea
- app.ResultTextArea.Value = mergedSentence;
- end
- % Button pushed function: SlovaiSuglasniciButton
- function SlovaiSuglasniciButtonPushed(app, event)
- sentence = app.EditField.Value;
- vowels = 'aeiouAEIOU';
- numVowels = sum(ismember(sentence, vowels));
- numNonVowels = sum(~ismember(sentence, vowels) & isletter(sentence));
- app.ResultTextArea.Value = sprintf('Broj slova: %d\nBroj suglasnika: %d\n', numVowels + numNonVowels, numNonVowels);
- end
- % Button pushed function:
- % BrojRecenicaBrojRijeciBrojSuglasnikaButton
- function BrojRecenicaBrojRijeciBrojSuglasnikaButtonPushed(app, event)
- sentence = app.EditField.Value;
- words = strsplit(sentence);
- result = '';
- vowels = 'aeiouAEIOU';
- for i = 1:length(words)
- word = words{i};
- numVowels = sum(ismember(word, vowels));
- result = [result, sprintf('Riječ: %s\n Broj slova: %d\n Broj samoglasnika: %d\n Samoglasnici: %s\n', ...
- word, length(word), numVowels, word(ismember(word, vowels)))];
- end
- app.ResultTextArea.Value = result;
- end
- end
- 5. Funckija sa omegom
- % Button pushed function: PrikaziButton
- function PrikaziButtonPushed(app, event)
- % Get parameter values from GUI
- T = app.TEditField.Value;
- omega = app.OmegaEditField.Value;
- phi = app.PhiEditField.Value;
- t_min = app.TminEditField.Value;
- t_max = app.TmaxEditField.Value;
- % Generate time vector
- t = linspace(t_min, t_max, 100);
- % Calculate function f(t)
- f = exp(-t/T) .* sin(omega*t + phi);
- % Plot the function
- plot(app.UIAxes, t, f);
- xlabel(app.UIAxes, 't');
- ylabel(app.UIAxes, 'f(t)');
- title(app.UIAxes, 'Prikaz funkcije');
- end
- end
- 6. Smajlic
- % Button pushed function: SretniButton
- function SretniButtonPushed(app, event)
- % Kreiranje koordinata za smajlića
- t = 0:pi/50:2*pi;
- x_head = 4 * cos(t);
- y_head = 4 * sin(t);
- x_eye1 = cos(t) - 2;
- y_eye1 = sin(t) + 1.5;
- x_eye2 = cos(t) + 2;
- y_eye2 = sin(t) + 1.5;
- t_mouth = pi:pi/50:2*pi;
- x_mouth = 3 * cos(t_mouth);
- y_mouth = 3 * sin(t_mouth);
- % Prikazivanje smajlića na UIAxes komponenti
- plot(app.UIAxes, x_head, y_head, 'LineWidth', 2, 'Color', 'yellow');
- hold(app.UIAxes, 'on'); % Drži trenutni grafikon
- plot(app.UIAxes, x_eye1, y_eye1, 'LineWidth', 2, 'Color', 'black');
- plot(app.UIAxes, x_eye2, y_eye2, 'LineWidth', 2, 'Color', 'black');
- plot(app.UIAxes, x_mouth, y_mouth, 'LineWidth', 2, 'Color', 'black');
- hold(app.UIAxes, 'off'); % Završi držanje grafikona
- end
- % Button pushed function: TuzniButton
- function TuzniButtonPushed(app, event)
- % Kreiranje koordinata za tužnog smajlića
- t = 0:pi/50:2*pi;
- x = 4 * cos(t);
- y = 4 * sin(t);
- t1 = 0:pi/50:2*pi;
- x1 = cos(t1) - 2;
- y1 = sin(t1) + 1.5;
- t2 = 0:pi/50:2*pi;
- x2 = cos(t2) + 2;
- y2 = sin(t2) + 1.5;
- t3 = pi:pi/50:2*pi;
- x3 = 3 * cos(t3);
- y3 = -3 * sin(t3) - 2.3;
- % Prikazivanje tužnog smajlića na UIAxes komponenti
- plot(app.UIAxes, x, y, 'LineWidth', 2, 'Color', 'yellow');
- hold(app.UIAxes, 'on'); % Drži trenutni grafikon
- plot(app.UIAxes, x1, y1, 'LineWidth', 2, 'Color', 'black');
- plot(app.UIAxes, x2, y2, 'LineWidth', 2, 'Color', 'black');
- plot(app.UIAxes, x3, y3, 'LineWidth', 2, 'Color', 'black');
- hold(app.UIAxes, 'off'); % Završi držanje grafikona
- end
- end
- 7. Zastava mijenja boju
- % Button pushed function: PromijeniBojuButton
- function PromijeniBojuButtonPushed(app, event)
- % Clear previous plot
- cla(app.UIAxes);
- % Generate random color for the flag
- color = rand(1, 3); % Random RGB color
- % Generate data
- t = 0:0.1:4*pi;
- y1 = 1/2*sin(t) - 1;
- y2 = 1/2*sin(t) + 1;
- % Plot on UIAxes
- hold(app.UIAxes, 'on');
- area(app.UIAxes, t, y2, 'FaceColor', color, 'EdgeColor', color);
- area(app.UIAxes, t, y1, 'FaceColor', color, 'EdgeColor', color);
- hold(app.UIAxes, 'off');
- % Set axes properties
- xlabel(app.UIAxes, 'X osa');
- ylabel(app.UIAxes, 'Y osa');
- title(app.UIAxes, 'Grafikon na UI Axes');
- axis(app.UIAxes, [-2 15 -2 2]); % Set axis limits
- end
- end
- 8. GUI sa matricom A, treba izaci B
- % Button pushed function: IzracunajButton
- function IzracunajButtonPushed(app, event)
- A_str = app.ElementiMatriceATextArea.Value;
- % Split the input string into lines
- lines = splitlines(A_str);
- % Initialize matrix A
- A = [];
- % Iterate through each line and convert to numbers
- for i = 1:numel(lines)
- line = strtrim(lines{i}); % Remove leading/trailing whitespace
- if ~isempty(line)
- row = str2double(strsplit(line)); % Convert line to numbers
- A = [A; row]; % Append row to matrix A
- end
- end
- % Check if A is empty or not a valid matrix
- if isempty(A) || any(isnan(A(:)))
- % Display error if input is not a valid matrix
- app.OutputTextArea.Value = 'Error: Invalid matrix input.';
- return;
- end
- % Calculate matrix B
- % a) Exclude the last column of A
- B_a = A(:, 1:end-1);
- % b) Exclude the first row of A
- B_b = A(2:end, :);
- % c) Change signs of elements in the intersection of last row and first column
- A(end, 1) = -A(end, 1);
- B_c = A;
- % Display matrix B in OutputTextArea
- app.ElementiMatriceBTextArea.Value = sprintf(['B (iskljucenje zadnje kolone):\n%s\n\nB (iskljucenje prvog reda):\n%s\n\nB (presjek' ...
- '):\n%s'], ...
- mat2str(B_a), mat2str(B_b), mat2str(B_c));
- end
- end
- 9. Trostrana piramida:
- % Button pushed function: PrikazipiramiduButton
- function PrikazipiramiduButtonPushed(app, event)
- height = app.VisinaPiramideEditField.Value;
- baseLength = app.DuzinaOsnoviceEditField.Value;
- % Calculate the vertices of the tetrahedron
- A = [0, 0, 0];
- B = [baseLength, 0, 0];
- C = [baseLength/2, baseLength*sqrt(3)/2, 0];
- D = [baseLength/2, baseLength*sqrt(3)/6, height];
- % Define the faces of the tetrahedron
- faces = [
- 1, 2, 3;
- 1, 3, 4;
- 1, 4, 2;
- 2, 3, 4
- ];
- % Plot the tetrahedron
- cla(app.UIAxes); % Clear previous plot
- hold(app.UIAxes, 'on');
- patch(app.UIAxes, 'Vertices', [A; B; C; D], 'Faces', faces, 'FaceColor', 'magenta', 'EdgeColor', 'k');
- view(app.UIAxes, 3); % Set 3D view
- axis(app.UIAxes, 'equal'); % Set equal axis scales
- xlabel(app.UIAxes, 'X');
- ylabel(app.UIAxes, 'Y');
- zlabel(app.UIAxes, 'Z');
- title(app.UIAxes, 'Tetrahedron');
- hold(app.UIAxes, 'off');
- end
- end