简体   繁体   中英

Matlab: How to use all the values of a matrix in a function

I am new to Matlab and programming and am hoping that someone can help me out or point me in the right direction with an issue I have run into.

I have a 240x320 matrix (tempK) derived from a thermal image. Each cell in the matrix contains the temperature value of the cosponsoring pixel from the thermal image. I have defined the following function:

function out=Planck_radconvers(lambda_,tempK)
C1 = 1.19e-16;
C2 = 1.44e-2;

out=C1/(lambda_^5*(exp(C2/(lambda_*tempK))-1))*1e-6;
end

I then tried to use this function by applying the following:

rad=planck(10.25e-6,tempK)

The issue is that I have only been able to figure out how to get "rad" to out put the result for a single cell in "tempK". However I need it to do this for every cell in "tempK" and I need the output of "rad" to be the same dimensions as "tempK" (ie I need each all the converted values from "tempK" to have the same cell locations in "rad").

Any help on this would be very much appreciated.

To do operations element-wise, use the dot before each symbol designating a matrix operation.

./
.*
.^

you can do it with two loops all you need is add two loops and compute every cell separately :

function out=Planck_radconvers(lambda_,tempK)
C1 = 1.19e-16;
C2 = 1.44e-2;
for i = 1:m
  for j = 1:n
     out(i,j)=C1/(lambda_^5*(exp(C2/(lambda_*tempK(i,j)))-1))*1e-6;
  end
end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM