简体   繁体   English

Matlab:如何在函数中使用矩阵的所有值

[英]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. 我是Matlab和程序设计的新手,希望有人可以帮助我,或为我遇到的问题指明正确的方向。

I have a 240x320 matrix (tempK) derived from a thermal image. 我有一个从热图像得出的240x320矩阵(tempK)。 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". 问题是我只能弄清楚如何获得“ rad”以将单个单元格的结果放入“ 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"). 但是,我需要它对“ tempK”中的每个单元格执行此操作,并且我需要“ rad”的输出与“ tempK”具有相同的尺寸(即,我需要将“ tempK”中所有转换后的值都具有相同的单元格“ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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