how to convert the temperature from matrix 4d?

2 views (last 30 days)
Hi, I have a matrix 4d, Size(T)=100 20 15 12, the dimensions are lat lon depth time. I need to convert the temperature Kelvin to Celsius but just in the first two dimensions. Please, how I do it? I have used "convtemp,but without success.
  1 Comment
James Tursa
James Tursa on 21 Oct 2016
Edited: James Tursa on 21 Oct 2016
I don't understand what you mean by "just in the first two dimensions". You only want one plane of your array converted from Kelvin to Celsius? I.e., you deliberately want to end up with an array that has a mixture of Kelvin and Celsius temperatures in it? If the 4D array has temperatures in it, why don't you want all of it converted?

Sign in to comment.

Answers (2)

TallBrian
TallBrian on 21 Oct 2016
Hi Camila,
Your data is 4-D which means that every data point corresponds to a point in dimensions. So, when you say, I need to convert just the first two dimensions, maybe you mean I need to convert the data for all points in the first two dimensions, but only for a single value in the 3rd and 4th dimensions, which would be a plane.
In any case, you can use the following code:
kelvin2celcius = @(x) x-273.15;
data = rand(100,20,15,12);
data_new = data;
data_new(:,:,1,1) = kelvin2celcius(data_new(:,:,1,1));
example_modified = data(1,1,1,1)-data_new(1,1,1,1)
example_unmodified = data(1,1,2,1)-data_new(1,1,2,1)
Here you can see only the first index of the 3rd and 4th dimension is modified.
-Brian

Camila Hashimoto
Camila Hashimoto on 21 Oct 2016
Hi Brian, thanks a lot!

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!