gpt4 book ai didi

c - 如何在 MATLAB 中构建 MEX 文件?

转载 作者:行者123 更新时间:2023-11-30 16:19:07 27 4
gpt4 key购买 nike

我需要在 MATLAB 代码中使用以下函数:

#include "mex.h"
#include <math.h>
#include <stdio.h>

float xFit_1931( float wave )
{
float t1 = (wave-442.0f)*((wave<442.0f)?0.0624f:0.0374f);
float t2 = (wave-599.8f)*((wave<599.8f)?0.0264f:0.0323f);
float t3 = (wave-501.1f)*((wave<501.1f)?0.0490f:0.0382f);
return 0.362f*expf(-0.5f*t1*t1) + 1.056f*expf(-0.5f*t2*t2)
- 0.065f*expf(-0.5f*t3*t3);
}
float yFit_1931( float wave )
{
float t1 = (wave-568.8f)*((wave<568.8f)?0.0213f:0.0247f);
float t2 = (wave-530.9f)*((wave<530.9f)?0.0613f:0.0322f);
return 0.821f*exp(-0.5f*t1*t1) + 0.286f*expf(-0.5f*t2*t2);
}
float zFit_1931( float wave )
{
float t1 = (wave-437.0f)*((wave<437.0f)?0.0845f:0.0278f);
float t2 = (wave-459.0f)*((wave<459.0f)?0.0385f:0.0725f);
return 1.217f*exp(-0.5f*t1*t1) + 0.681f*expf(-0.5f*t2*t2);
}

此函数是用 C 语言编码的,因此我尝试构建一个 MEX 文件,但收到此错误消息:

>> mex CMfunction.c
Building with 'lcc-win32'.
Error using mex
c:\users\ya7yawii\appdata\local\temp\mex_1695753636261_3832\cmfunction.obj
.text: undefined reference to '_expf'
Specified export _mexFunction is not defined
Missing exports. Aborting

最佳答案

我刚刚使用下面论文 Simple Analytic Approximations to the CIE XYZColor Matching Functions 中的数学方程在 matlab 代码中重写了这些函数.

function int = xFit_1931(wave)
t1 = 0.0624.*(1-heaviside(wave-442.0))+0.0374.*heaviside(wave-442.0);
t2 = 0.0264.*(1-heaviside(wave-599.8))+0.0323.*heaviside(wave-599.8);
t3 = 0.0490.*(1-heaviside(wave-501.1))+0.0382.*heaviside(wave-501.1);
int = 0.362.*exp(-0.5.*((wave-442.0).*t1).^2)+1.056.*exp(-0.5.*((wave-599.8).*t2).^2)-0.065.*exp(-0.5.*((wave-501.1).*t3).^2);
end

function int = yFit_1931(wave)
t1 = 0.0213.*(1-heaviside(wave-568.8))+0.0247.*heaviside(wave-568.8);
t2 = 0.0613.*(1-heaviside(wave-530.9))+0.0322.*heaviside(wave-530.9);
int = 0.821.*exp(-0.5.*((wave-568.8).*t1).^2)+0.286.*exp(-0.5.*((wave-530.9).*t2).^2);
end

function int = zFit_1931(wave)
t1 = 0.0845.*(1-heaviside(wave-437.0))+0.0278.*heaviside(wave-437.0);
t2 = 0.0385.*(1-heaviside(wave-459.0))+0.0725.*heaviside(wave-459.0);
int = 1.217.*exp(-0.5.*((wave-437.0).*t1).^2)+0.681.*exp(-0.5.*((wave-459.0).*t2).^2);
end

关于c - 如何在 MATLAB 中构建 MEX 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55696772/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com