how to calculate mean values of a variable in a table in matlab

To calculate the mean values of a variable in a table in MATLAB, you can use the mean function along with table indexing. Here is an example:

main.m
% Create a table
data = table([10; 20; 30; 40], [5; 15; 25; 35], 'VariableNames', {'Var1', 'Var2'});
disp(data);

% Calculate the mean values
mean_Var1 = mean(data.Var1);
mean_Var2 = mean(data.Var2);

% Display the mean values
disp(mean_Var1);
disp(mean_Var2);
261 chars
12 lines

In this example, the table function is used to create a table with two variables Var1 and Var2. The mean function is then used to calculate the mean values of each variable. Finally, the mean values are displayed using the disp function.

Note that you need to replace data with the actual name of your table and Var1 and Var2 with the names of your variables.

Running this code will display the table as well as the mean values of each variable.

related categories

gistlibby LogSnag