[r c] = size(trial_03) in matlab

The code [r c] = size(trial_03) returns the number of rows (r) and columns (c) of the matrix trial_03.

In MATLAB, the size() function is used to get the dimensions of arrays, tables, and variables. The output of size() is an array containing the length of each dimension of the input.

Using square brackets ([]) around r c on the left-hand side of the equals sign captures both values returned by size().

For example, if trial_03 is a 3x4 matrix, the code [r c] = size(trial_03) would set r = 3 and c = 4.

Here is an example:

main.m
% create a 3x4 matrix
trial_03 = [1 2 3 4; 5 6 7 8; 9 10 11 12];

% find the size of the matrix and store values in r and c
[r, c] = size(trial_03);

% display the number of rows and columns
disp(['Number of rows: ' num2str(r)])
disp(['Number of columns: ' num2str(c)])
270 chars
10 lines

This would output:

main.m
Number of rows: 3
Number of columns: 4
39 chars
3 lines

related categories

gistlibby LogSnag