在MATLAB中运行程序后出现:Error: Missing variable or function,我又找不着程序错误在哪??谢谢!!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在MATLAB中运行程序后出现:Error: Missing variable or function,我又找不着程序错误在哪??谢谢!!相关的知识,希望对你有一定的参考价值。
function [y,fval]=assign_math(C)
C=C';
f=C(:);
[m,n]=size(C);
Aeq=zeros(2*n,n*n);
for i=1:n
Aeq(1:n,1+(i-1)*n:i*n)=eye(n,n);
end
for i=1:n
Aeq(n+i,1+(i-1)*n:i*n)=ones(1,n);
end
beq=ones(2*n,1);
lb=zeros(n*n,1);
ub=ones(n*n,1);
x=linprog(f,[],[],Aeq,beq,lb,ub);
y=reshape(x,n,n);
y=y';
y=round(y);
sol=zeros(n,n);
for i=1:n
for j=1:n
if y(i,j)==1
sol(i,j)=C(j,i);
end
endendfval=sum(sol(:));
??? Undefined command/function 'assign_math'.
??? Input argument "C" is undefined.
Error in ==> Untitled at 2
C=C';
还是不行呢。。。郁闷啊
C=C';
f=C(:);
[m,n]=size(C);
Aeq=zeros(2*n,n*n);
for i=1:n
Aeq(1:n,1+(i-1)*n:i*n)=eye(n,n);
end
for i=1:n
Aeq(n+i,1+(i-1)*n:i*n)=ones(1,n);
end
beq=ones(2*n,1);
lb=zeros(n*n,1);
ub=ones(n*n,1);
x=linprog(f,[],[],Aeq,beq,lb,ub);
y=reshape(x,n,n);
y=y';
y=round(y);
sol=zeros(n,n);
for i=1:n
for j=1:n
if y(i,j)==1
sol(i,j)=C(j,i);
end
end
end
fval=sum(sol(:));
以上这些放在m文件里,文件名为assign_math.m
在命令行里写:
a=[0.4714 0.2628 0.7246 0.3312 0.3626 0.2136 0.2072 0 0 0
0.8146 0.4504 0.4286 0.3980 0.1766 0.0900 0.1864 0 0 0
0.6334 0.5568 0.3246 0.3624 0.3890 0.2608 0.2444 0 0 0
0.4334 0.5088 0.3394 0.4154 0.4282 0.0900 0.3152 0 0 0
0.8146 0.5596 0.4394 0.3920 0.2886 0.1440 0.3844 0 0 0
0.5258 0.5588 0.3550 0.3724 0.3290 0.0900 0.3488 0 0 0
0.4858 0.3824 0.7098 0.6460 0.4314 0.3720 0.0116 0 0 0
0.5938 0.2628 0.5470 0.6460 0.0814 0.4500 0.3552 0 0 0
0.4146 0.3612 0.6502 0.2484 0.4194 0.4900 0.3856 0 0 0
0.6250 0.4644 0.4638 0.2460 0.4486 0.4900 0.2660 0 0 0];
[y fval]=assign_math(a)
回车,就可以运行
结果:
Optimization terminated.
y =
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
fval =
1.3410
你是按照我说的一步步做的吗?注意MATLAB上面有个路径(默认一般是C:/matlab/work),assign_math.m文件要放在这个路径下 参考技术A 朋友,MATLAB的基本概念:
以function开头的程序,是描述该函数的内容,应该放在与主程序同样的目录下,文件命名为 xxx.m,xxx可以是任何名字,函数名称可以自己取,比如你的assign_math, 可以与文件名称不一样。
这样写主程序的时候,就可以调用已经写好函数assign_math,MATLAB会自动在当前目录下找到该函数所在的 xxx.m 文件的。
运行exe4j打包好的java桌面应用程序后出现error.log日志错误
java.io.IOException: Cannot run program "c:\docume~1\admini~1\??\demo\bin\mysql/StopMySQL.bat": CreateProcess error=123, ????????????ò?í±ê
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.vivoinfo.steelmis.View.Main$1.windowClosing(Main.java:250)
at java.awt.AWTEventMulticaster.windowClosing(Unknown Source)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JFrame.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=123, ????????????ò?í±ê
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 20 more
StopMySQL.bat是我写的调用mysql服务的bat文件,c:\docume~1\admini~1\??显示的真正编码是:C:\Documents and Settings\Administrator\桌面\
但每次运行exe执行文件后就出现这样的错误日志,很头疼,不知道怎么解决!希望大家尽快帮助我!不胜感激!!
我在不是中文的目录下点击exe执行文件完全正常啊!
以上是关于在MATLAB中运行程序后出现:Error: Missing variable or function,我又找不着程序错误在哪??谢谢!!的主要内容,如果未能解决你的问题,请参考以下文章
怎么将图片导入matlab中?让图片出现在程序中?如果要存入matlab路径,该存入哪个路径?
尝试在 MI MAX 2 android 设备上运行 react-native 应用程序时应用程序期间出现 SecurityException:installDebug 任务