Within a separated time-series, how do I produce a loop that calculates temperature change between fortnightly water profiles?

1 vue (au cours des 30 derniers jours)
I am currently trying to create a code that calculates the difference in temperature between several fortnightly water profiles. I have a 1x124 cell called 'ca' and in each first column cell of the first row are other closed arrays with the depth and temp readings. They are known as ca{1,1} for the first double array, ca{1,2} for the second and so on. I have the code: ca{1,1}(:,2)-ca{1,2}(:,2)
which takes the second set of temperatures from the first. How can I create a loop that will calculate the temperature change from the previous fortnightly reading for all 124 dates?
Another problem is where the profile depth maximums are not the same and I get the error - Matrix dimensions must agree. Can this be bypassed as well?
Many thanks in advance, Josh

Réponse acceptée

Astarag Chattopadhyay
Astarag Chattopadhyay le 12 Juin 2017
Hi,
You can resolve the first issue you are facing by using the following code snippet:
a=zeros(x,109); // x equals to the number of rows in temperature column of 'ca'
for i=1:123
a(:,i) = ca{1,i}(:,2)-ca{1,i+14}(:,2)
if (i+14)==123
break;
end
end
display(a);
Here, the loop starts with the first entry of the cell array 'ca' and accesses the temperature column(second column) of the array residing in that location 'ca{1,1}'. Then it finds the difference between the temperature of all the rows from that array and temperature of all the rows of the array which is 14 entries away from that location. The result of subtraction is getting stored in a (x * 109) size array where x is the number of rows in the temperature column of 'ca'. Also a check is implemented using 'if' to check if the maximum entry in 'ca' is reached or not.
The second issue what I understood is that the number of entries are different for every array. In this case you can fix a number of rows to subtract, not subtracting all the rows. If it does not affect your functionality. You can fix the row number as the number of rows of the array having the minimum among all.
  2 commentaires
Joshua Payne
Joshua Payne le 12 Juin 2017
Thank you so much Astarag Chattopadhyay. This works well. The depth entries are different yes but the main issue is them starting at different depths too. Would an interp1 sort this problem out or another code?
Many thanks, Josh
Astarag Chattopadhyay
Astarag Chattopadhyay le 13 Juin 2017
I think you got it right, interp1 would be apt to solve this issue, but you need to be careful while choosing the query points. Take into consideration all the starting and ending depth points while deciding the query points.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by