Info

This question is closed. Reopen it to edit or answer.

Basic question about loops

1 view (last 30 days)
Marlon Calispa
Marlon Calispa on 26 Dec 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi, I am really new in matlab. I want to do the next:
I have one raster (100*100) file and rainfall data for n numbers of weeks, I want to estimate a new variable for each pixel in the dame domain of my raster file (i,j) for every timestep (k) in this case my number of weeks (2080)
The new variable is a linear relation between the current value of the variable (k) and the previous time step (k-1) in every timestep.
So, I decided to use loops, one for rows, one for columns, since I need to update the value of each pixel, and I am able to run the model for every pixel, but how can I considered time in this case, to do the the same thing (update all pixels) but every week in my data period.
I was thinking in use three loops, one for weeks, one for rows and one for columns, but I have no idea how to tell matlab, to use the value of pixel (i,j) for a certain timestep (k).
Apologies for such a simple question, but as I mentioned these are my first steps in to this application.

Answers (1)

Image Analyst
Image Analyst on 27 Dec 2014
Create a 3D array by putting each one of the n (2080) 2-D images into one slice of a 3D array.
array3d = zeros(100,100,2080);
for k = 1 : 2080
filename = sprintf('data file %d', k); % Whatever....
array2d = readYourFile(whatever....)
array3d(:,:,k) = array2d;
end
So now you have a 100 by 100 by 2080 3D array. Then use diff()
newVariable = someLinearFactor * diff(array3D, 1, 3);
This will make a new 3D array where each pixel is a value, labeledImage, times the difference between one time point and another, and it does that for every pixel laterally. So you will have a 100x100x2079 array.

Community Treasure Hunt

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

Start Hunting!