要使用matlab链接java,我使用了一个开源的Matlab Control谷歌代码
我收到此错误:Error: At least one END is missing: the statement may begin here.
从命令行javac Dwtembed.java运行此代码
很明显,如果您复制粘贴以下代码并检查,您将了解我实际上想要做什么。我真的希望得到一些帮助来解决这个问题。
import matlabcontrol.*;
class Dwtembed
{
public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
//Create a proxy, which we will use to control MATLAB
MatlabProxyFactory factory = new MatlabProxyFactory();
MatlabProxy proxy = factory.getProxy();
proxy.eval("file_name='lena.bmp';");
proxy.eval("cover_object=double(imread(file_name));");
proxy.eval("mc=size(cover_object,1);");
proxy.eval("nc=size(cover_object,2);");
proxy.eval("file_name='dmg2.bmp';");
proxy.eval("message=double(imread(file_name));");
proxy.eval("mm=size(message,1);");
proxy.eval("nm=size(message,2);");
proxy.eval("[ca,ch,cv,cd]=dwt2(cover_object,'haar');");
proxy.eval("ca1=ca;");
proxy.eval("qiangdu=1;");
proxy.eval("for i=1:nm");
proxy.eval("for j=1:nm");
proxy.eval("if(message(i,j)==0)");
proxy.eval("ca1(i,j)=ca(i,j)+qiangdu;");
proxy.eval("end");
proxy.eval("end");
proxy.eval("end");
proxy.eval("watermarked_image=idwt2(ca1,ch,cv,cd,'haar');");
proxy.eval("watermarked_image_round=round(watermarked_image);");
proxy.eval("watermarked_image_uint8=uint8(watermarked_image_round);");
proxy.eval("imshow(watermarked_image_uint8);");
proxy.eval("figure(2);");
proxy.eval("imshow(watermarked_image_uint8,[]);");
proxy.eval("title('watermarked image');");
proxy.eval("imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');");
proxy.eval("xsz=mc*nc*max(max(cover_object.^2))./sum(sum((cover_object-watermarked_image_round).^2));");
proxy.eval("psnr=10*log10(xsz);");
//Disconnect the proxy from MATLAB
proxy.disconnect();
}
}
答案 0 :(得分:0)
您不能eval
for
和if
这样,因为for i=1:nm
本身不是有效的MATLAB语句。你需要eval
完成MATLAB语句的事情。
尝试将for
或if
语句的全部内容放在一个eval
中。