how to convert the temperature from matrix 4d?

2 次查看(过去 30 天)
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 个评论
James Tursa
James Tursa 2016-10-21
编辑:James Tursa 2016-10-21
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?

请先登录,再进行评论。

回答(2 个)

TallBrian
TallBrian 2016-10-21
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 2016-10-21
Hi Brian, thanks a lot!

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by