1. Syntax [X, Y] = meshgrid(x, y) x = linspace(0, 2 * pi, 100); y = linspace(0, 2 * pi, 100); [X, Y] = meshgrid(x, y); Z = cos(X) + sin(Y); mesh(X, Y, Z) xlabel('x') ylabel('y') zlabel('z') colorbar; Reference: https://www.mathworks.com/help/matlab/ref/meshgrid.html
1. Syntax subplot(x축, y축, 위치) x = linspace(0, 10); for i = 1:1:4 y = cos(2 * i * x); subplot(2, 2, i) plot(x, y) xlabel('x') ylabel('y') title(i); end 2. Subplots with Different Sizes subplot(2,2,1); x = linspace(-3.8,3.8); y_cos = cos(x); plot(x,y_cos); title('Subplot 1: Cosine') subplot(2,2,2); y_poly = 1 - x.^2./2 + x.^4./24; plot(x,y_poly,'g'); title('Subplot 2: Polynomial') subplot(2,2,[3,4..
1. Syntax plot(x축, y축) x = linspace(0, 4 * pi, 1000); y = cos(x); plot(x, y) 2. Label axis x = linspace(0, 4 * pi, 1000); y = cos(x); plot(x, y, 'r:', 'LineWidth', 5) xlabel('x축', 'fontsize',20) ylabel('y축') 3. Adding new plot x = linspace(0, 4 * pi, 1000); y = cos(x); plot(x, y, 'r:', 'LineWidth', 5) xlabel('x축', 'fontsize',20) ylabel('y축') title('xy 그래프') hold on y2 = sin(x) plot(x, y2) hold o..
1. Syntax a = [1 2 3 1 0 1]; for i = 1:1:length(a) if a(i) == 1 disp('a는 1입니다.') elseif a(i) == 0 disp('a는 0입니다.') else disp('a는 1이 아닙니다.') end end 2. Evaluate Multiple Conditions in Expression x = 10; minVal = 2; maxVal = 6; if (x >= minVal) && (x maxVal) disp('Value exceeds maximum value.') else disp('Value is below minimum value.') end Reference: https://www.mathworks.com/help/matlab/ref/if.h..
1. Syntax for 시작값:증감값:종료값 구문end total = 0; for i = 1:2:10 total = total + i; end disp(total); ☞ 증감값을 명시하지 않은 경우에는 1이 default 2. Execute Statements for Specified Values 각 배열의 원소마다 실행 for v = [1 5 8 17] disp(v) end3. Repeat Statements for Each Matrix Columns행렬의 경우는 각 열마다 실행 for I = eye(4,3) disp('Current unit vector:') disp(I) end Reference: https://www.mathworks.com/help/matlab/ref/for.html
함수의 정의만을 포함하는 함수 파일에서 정의 가능함수 파일의 이름은 첫번째 함수의 이름과 같아야 함스크립트 파일에서는 맨 뒤에 함수 정의 1. Function with One Output function y = sumAB(x1, x2) y = x1 + x2; end 2. Function with Multiple Output function [add, substract] = OperatorXY(x, y) add = x + y; substract = x - y; end Reference: https://www.mathworks.com/help/matlab/ref/function.html
1. flipud(array) 상하 반전 flip up to down a = [1 2 3; 4 5 6; 7 8 9; 10 11 12] b = flipud(a) 2. fliplr(array)좌우 반전 flip left to right a = [1 2 3; 4 5 6; 7 8 9; 10 11 12] c = fliplr(a) 3. reshape(array, column, row)행렬의 형태를 변경 1 * x 형태의 배열로 만든 후 해당 모양으로 잘라 만듦열부터 합쳐서 1 * x를 만듦ex) [1 2; 3 4; 5 6] ☞ [1 3 5 2 4 6] a = [1 2 3; 4 5 6; 7 8 9; 10 11 12] % 행렬 형태 변환 b = reshape(a,1, 12); c = reshape(a, 3, 4); R..
1. Array Creation 배열 생성열은 "," 또는 "스페이스" 로 구분행은 ";" 으로 구분 a = [1 2 3; 4 5 6; 7 8 9]2. Matrix and Array Operation더하기, 빼기각각의 원소에 연산을 적용 a = [1 2 3; 4 5 6; 7 8 9] a + 10 b = [10 11 12; 13 14 15; 16 17 18] a + b 곱하기 행렬끼리의 곱은 행렬의 곱을 반환각각의 원소에 연산을 적용하려면 ".*"을 사용 a = [1 2 3; 4 5 6; 7 8 9] a * 10 b = [10 11 12; 13 14 15; 16 17 18] a * b a .* b 전치 행과 열을 바꾸는 것 a = [1 2 3; 4 5 6; 7 8 9] a' 3. Indexing인덱싱행렬의..