Info

此问题已关闭。 请重新打开它进行编辑或回答。

Hi, I have a three questions about loops. The question I attempted was 'Create normal random data for 10 rows and 5 columns. Compute the means and standard deviations of each row by using a loop. Display the results for each row.'

1 次查看(过去 30 天)
The answer is
Create normal random data for 10 rows and 5 columns.
Compute the means and standard deviations of each row by using a loop.
Display the results for each row.
%}
data = randn([10 5])
for i = 1:size(data,1)
m = mean(data(i,:),2);
s = std (data(i,:),[],2);
disp('Row data:')
disp(m)
disp(s)
end
My questions are
1)What does size mean in this context (for i)?
2)What does mean(data(i, : ), 2); mean?
3)What does std (data(i, : ), [] 2); mean? And why are the [] square brackets used here?
  1 个评论
Mehmed Saad
Mehmed Saad 2020-5-16
编辑:Mehmed Saad 2020-5-16
The best way of understanding that is
  1. Open MATLAB
  2. On the top right corner in MATLAB app, there's a search documentation field. Type size in it. it will show you array size, read that document
  3. After that, read Array Indexing, mean and std by following step 2
  4. There are examples given in each document, read those examples for better understanding
  5. Also you can get help on any MATLAB command by typing help size (or whatever command you want to see)
help size
size Size of array.
D = size(X), for M-by-N matrix X, returns the two-element row vector
D = [M,N] containing the number of rows and columns in the matrix.
For N-D arrays, size(X) returns a 1-by-N vector of dimension lengths.
Trailing singleton dimensions are ignored.
.
.
.
See also length, ndims, numel.
Reference page for size
Other functions named size

回答(1 个)

Walter Roberson
Walter Roberson 2020-5-16
  1. size(data,1) is number of rows
  2. mean(something, 2) is mean along the columns. The number of columns will be reduced to 1, with the other dimensions remaining the same as they were.
  3. std() along the columns. The [] exist to occupy an argument so that MATLAB can tell the difference between giving information about which normalization scheme to use (normalize by N-1 or normalize by N), versus giving information about which dimension to act along.

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by