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 (type-name) expression #include int main() { int math = 90, korean = 95, english = 96; int sum = math + korean + english; double avg = (double)sum / 3; // 정수 / 정수 = 정수 // 실수 / 정수 = 실수 // 실수 / 실수 = 실수 // 정수 + 정수 = 정수 // 정수 + 실수 = 실수 // 실수 + 실수 = 실수 printf("%f\n", avg); // 93.666667 return 0; } Reference: https://en.cppreference.com/w/c/language/cast
1. char 8비트(1바이트) 문자를 담는데 사용 2. short16비트(2바이트) 정수를 담는데 사용 3. int32비트(4바이트) 운영체제의 환경에 따라 사용되는 비트 수가 다름예) 16비트 컴퓨터에서는 16비트로 사용됨정수를 담는데 사용 #include int main() { int ia = 5; int ib = 3; int iSum = ia + ib; int iSubstract = ia - ib; int iMultiply = ia * ib; int iQuotient = ia / ib; int iReminder = ia % ib; printf("%d + %d = %d\n", ia, ib, iSum); printf("%d - %d = %d\n", ia, ib, iSubstract); printf("..
1. Syntax // 한 줄 주석 /* 여러 줄 주석 */코드 실행시 컴파일러가 무시하는 부분으로서 코드 가독성을 늘리기 위해 사용 #include /* C-style comments can contain multiple lines. */ /* Or, just one line. */ // C++-style comments can comment one line. // Or, they can // be strung together. int main(void) { // The below code won't be run // puts("Hello"); // The below code will be run puts("Hello"); } Reference: https://en.cppreference.com/w/c..
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