24小时热门版块排行榜    

查看: 479  |  回复: 0

无知为知

新虫 (初入文坛)

[求助] vc++6.0计算矩阵

我用vc++6.0调用matlab engine计算矩阵M*N,,不知为什么结果全是0。,请大家帮忙,看看程序错在哪里!
#include
#include
#include
#include
#include
#include "engine.h"
#include "math.h"
#include "stdio.h"

Engine* ep ;
mxArray *temp1=mxCreateDoubleMatrix(1,1,mxREAL);
double s0,s1,s2,s3;

int main()
{
               
        fprintf(stderr, "╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\n";
        fprintf(stderr, "╬                                    ╬\n";
        fprintf(stderr, "╬   Starting MATLAB engine,please wait..   ╬\n";
        fprintf(stderr, "╬                                    ╬\n";
        fprintf(stderr, "╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\n";
        if (!(ep = engOpen("\0"))
        {
                fprintf(stderr, "\nCan't start MATLAB engine\n";
                return 0;
        }
     //实现vc向matlab输送确定的矩阵
         double M[4]={-11,1,2,14};
     mxArray *m=mxCreateDoubleMatrix(2,2,mxREAL);
     memcpy((void *)mxGetPr(m), (void *)M, sizeof(M));
         engPutVariable(ep,"m",m);

         double N[4]={-1,5,2,10};
     mxArray *n=mxCreateDoubleMatrix(2,2,mxREAL);
     memcpy((void *)mxGetPr(n), (void *)N, sizeof(N));
         engPutVariable(ep,"n",n);

    engEvalString(ep,"E=M*N;";

    engEvalString(ep,"vsc_s0=E(1:1,1:1);";
    engEvalString(ep,"vsc_s1=E(1:1,2:2);";
    engEvalString(ep,"vsc_s2=E(2:2,1:1);";
        engEvalString(ep,"vsc_s3=E(2:2,2:2);";


        temp1=engGetVariable(ep,"vsc_s0";
        s0=*(mxGetPr(temp1));
        temp1=engGetVariable(ep,"vsc_s1";
        s1=*(mxGetPr(temp1));
        temp1=engGetVariable(ep,"vsc_s2";
        s2=*(mxGetPr(temp1));   
        temp1=engGetVariable(ep,"vsc_s3";
        s3=*(mxGetPr(temp1));

        printf("vsc_s0=%e\n",s0);
        printf("vsc_s1=%e\n",s1);
        printf("vsc_s2=%e\n",s2);
        printf("vsc_s3=%e\n",s3);

        engClose(ep);
        return 1;
}
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

相关版块跳转 我要订阅楼主 无知为知 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 建议基金发布提前给出明确的时间点 +10 kulium 2026-08-21 13/650 2026-08-21 21:58 by alongwaytogo
[基金申请] 2026国自然函评费到账 +7 羊腰板 2026-08-21 7/350 2026-08-21 21:28 by iwuli
[基金申请] 今日不放榜?网传国自然预计 8 月 27 日可查结果 +16 医学老男孩 2026-08-20 20/1000 2026-08-21 21:13 by Ldrop2023
[基金申请] 科研孤儿太难了 +17 我4大白菜 2026-08-20 18/900 2026-08-21 20:57 by zhangev
[基金申请] 看来今天不会放榜了? +8 chengyan1220 2026-08-21 11/550 2026-08-21 17:52 by dcqxinyang
[基金申请] 让我中一个面上吧! +11 大萍1987 2026-08-20 13/650 2026-08-21 14:48 by 20120902066
[基金申请] 人气不行了 +7 fansofjerry 2026-08-21 7/350 2026-08-21 14:13 by Vivilian
[基金申请] 只有每年这种时候来逛逛小木虫 +23 yaoyewhu2008 2026-08-20 25/1250 2026-08-21 12:19 by Poppy1104
[基金申请] 什么时候开奖? +7 CrisMessi 2026-08-18 7/350 2026-08-21 12:15 by weiyin
[基金申请] 今天放榜没戏了吧 +9 yuleib84 2026-08-19 11/550 2026-08-21 10:06 by gltch
[基金申请] 基金啊基金 +4 longfie172 2026-08-20 4/200 2026-08-21 08:58 by mark mao
[基金申请] 放榜前的不淡定 40+4 snowwithsea 2026-08-19 13/650 2026-08-21 08:30 by 北京莱茵编辑
[基金申请] 估计是周四 +3 archvillain 2026-08-18 3/150 2026-08-21 01:48 by jnhyjjm
[基金申请] 今天系统多次维护,明天很可能放榜! +10 zju2000 2026-08-16 11/550 2026-08-20 20:02 by cl479861084
[基金申请] 时间戳变了,能看出什么问题? +18 基诺咪客 2026-08-17 23/1150 2026-08-20 17:19 by Godzela
[基金申请] 重要消息,中午系统在维护 +11 yuleib84 2026-08-18 12/600 2026-08-20 11:09 by xskun
[基金申请] 今天放榜吗? +14 布布和一二 2026-08-19 15/750 2026-08-19 18:07 by gltch
[基金申请] 朋友圈看到的 +6 wangzilk 2026-08-18 8/400 2026-08-19 10:55 by Haru815
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
信息提示
请填处理意见