Info
This question is closed. Reopen it to edit or answer.
How to create a loop for a matrix?
1 view (last 30 days)
Show older comments
Hello I have a November month daily data for 10 stations, matrix of dimension (630*10) from year 1995 to 2015 i.e 1 to 30 rows for November year 95 than next 30 rows for year 96 and so on. I want to find 95th percentile for each year and for each station so that my new matrix dimension(21*10). I want to create a loop for this such that loop will pick up first 30 values and find the percentile than next 30 values and so on.
0 Comments
Answers (1)
Jan
on 30 Sep 2016
Edited: Jan
on 30 Sep 2016
result = zeros(21, 10);
cursor = 0;
for k = 1:30:630
startIndex = k;
endIndex = k + 30;
cursor = cursor + 1;
result(cursor, :) = YourCalculations(data(startIndex:endIndex, :));
end
Or in a convenient Matlabish way:
siz = size(data);
data = reshape(data, [30, siz(1) / 30, siz(2)]);
result = prctile(data, 95, 1);
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!