- Open MATLAB
- 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
- After that, read Array Indexing, mean and std by following step 2
- There are examples given in each document, read those examples for better understanding
- Also you can get help on any MATLAB command by typing help size (or whatever command you want to see)
Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Mehmed Saad
el 16 de Mayo de 2020
Editada: Mehmed Saad
el 16 de Mayo de 2020
The best way of understanding that is
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
Respuestas (1)
Walter Roberson
el 16 de Mayo de 2020
- size(data,1) is number of rows
- 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.
- 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.
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!