필터 지우기
필터 지우기

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