Matlab gui 读入图像,程序如下,出现了很畸形的错误,Matlab居然提示了如此多错误error,求破

Matlab gui 读入图像,程序如下,出现了很畸形的错误,Matlab居然提示了如此多错误error,求破,第1张

在否?貌似你的GUI还用了pushbutton什么的,你的程序应该没什么问题,我想可能是你的一些属性的设置有问题,比如说坐标轴的Tag改正确了吗?要不你把你的GUI文件夹打包发给我,我来看看能不能解决。396430539@qqcom

你发给我的文件,我有看过,不知道什么原因。我给你发了一个我曾经做的图像处理的例子,希望对你有所帮助。祝好!

Matlab GUI 软件交互界面的初级 *** 作无非是用户输入数据或者,然后程序接收到这些数据或者后,经过运算,最后在界面上输出计算后的数据或者。通过一个简单的加法计算器的例子来演示输入数据,数据处理和输出数据,给自学者参考借鉴。

1首先,在命令行窗口输入guide,按回车键会跳出GUI创建选项,选择创建一个新的空白的GUI。

        2创建好GUI后,会跳出如下的界面。左边一列是可供选择的控件,比如想要建立一个按钮,那就选中按钮这个控件后拖到右边的区域即可。这个例子会用到按钮、可编辑文本和静态文本。

       3先拖三个可编辑文本到右边区域如下图。

4 然后对可编辑文本框进行编辑,编辑的方法是双击它,会跳出如下图的属性编辑器。其中,“string”一栏对应的是可编辑文本框中的内容;“Tag”一栏是该可编辑文本框的标签(名字);“Fontsize”一栏是可编辑文本框中的字体大小。其他的属性还有很多,这次用不到,不一一介绍了。

5将“string”一栏的内容删掉;将“Fontsize”一栏改为20,让字体大一点,可编辑文本框是可以拉大的,如果框太小而字体太大,就把框拉大一点。同理,在三个可编辑文本框的中间拉两个静态文本框,将它们的“string”一栏分别改为“+”和“=”,同样将“Fontsize”一栏改为20。效果如下图。

6拖入一个按钮到布局中,双击它,将“string”一栏改为“计算”,字体也设为20号。如下图。

7正常情况下每个GUI都得有按钮这个控件,因为在你输入参数或者后,得有 *** 作来启发程序运算。我们右击按钮,找到“查看回调”里面的“callback”,点击它,就会进入按钮的回调函数。将你想要的运算程序放到按钮的回调函数中,当你点击按钮后,按钮的回调函数中的程序就会开始运行。

        8在按钮回调函数中敲入如图的程序段。其中get()表示获取某个值,在这里就是获取可编辑文本框中的“string”,然后利用str2double()函数将字符型转换成数值。如此一来,edit1(最左边的可编辑文本框)的内容就读取到变量a,edit2(中间的可编辑文本框)的内容就读取到变量b。令c=a+b,然后利用set()函数将edit3(最右边的可编辑文本框)的“string”值设为c,要注意的是,这里需要利用num2str()函数将c从数值型再转换成字符型。

9到这里就大功告成了。点击运行,然后往edit1和edit2里面输入数据,点击计算按钮,edit3就会显示计算结果啦。

GUI程序一开始最大化,在outputfcn函数的最后添加如下语句,

javaFrame = get(gcf,'javaFrame');

set(javaFrame,'Maximized',1);

只有矩形有圆形能移动,其它实现起来麻烦点,办法有的只是代码太多。

画圆弧改成了画曲线,圆弧稍麻烦,当然方法是很简单的,你可以自己思考一下。

双击13个颜色中的任意一个都会d出颜色选择器。

有保存与打开功能。扩展名请用 jdr

基本满足条件,细节可能不是很好,另,代码比较乱,怕不好看懂咯,呼呼。

import javaawt;

import javaawtevent;

import javaawtgeom;

import javaawtimageBufferedImage;

import javaio;

import javautilArrayList;

import javaxswing;

import javaxswingfilechooserFileNameExtensionFilter;

public class JDraw {

public static void main(String[] args) {

JFrame f=new JFrame();

fsetDefaultCloseOperation(3);

fsetSize(880,600);

fsetLocationRelativeTo(null);

fgetContentPane()add(Mc);

fgetContentPane()add(Mm,"South");

fsetVisible(true);

}

}

class CVS extends Component implements ComponentListener,MouseListener,MouseMotionListener{

public void componentHidden(ComponentEvent e) {}

public void componentMoved(ComponentEvent e) {}

public void componentResized(ComponentEvent e) {resized();}

public void componentShown(ComponentEvent e) {}

private void resized() {

int w=thisgetWidth();

int h=thisgetHeight();

tbuff=new BufferedImage(w,h,3);

makeBuff(w,h);

}

private void makeBuff(int w,int h) {

Graphics g = tbuffgetGraphics();

gdrawImage(buff,0,0,null);

gdispose();

buff=new BufferedImage(w,h,3);

g=buffgetGraphics();

gdrawImage(tbuff,0,0,null);

gdispose();

}

BufferedImage buff,tbuff;

CVS(){

thisaddComponentListener(this);

thisaddMouseListener(this);

thisaddMouseMotionListener(this);

buff=new BufferedImage(1,1,3);

}

public void paint(Graphics gr){

Graphics2D g = buffcreateGraphics();

gsetBackground(new Color(0xff000000,true));

gclearRect(0,0,getWidth(),getHeight());

gsetRenderingHint(RenderingHintsKEY_ANTIALIASING,

RenderingHintsVALUE_ANTIALIAS_ON);

MsadrawAll(g);

if(Mts!=null)

Mtsdraw(g);

gdispose();

grdrawImage(buff,0,0,this);

grdispose();

}

public void mouseClicked(MouseEvent e) {}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mousePressed(MouseEvent e) {

Mmp(egetPoint());

}

public void mouseReleased(MouseEvent e) {

Mmr(egetPoint());

}

public void mouseDragged(MouseEvent e) {

Mmd(egetPoint());

}

public void mouseMoved(MouseEvent e) {}

}

class Menu extends JComponent implements MouseListener,ActionListener{

JComboBox sbox,method;

CLabel[] cl;

JCheckBox fillC,drawB;

JRadioButton fc,bc;

ButtonGroup bg;

JButton clear,up,down,save,load;

Menu(){

thissetLayout(new FlowLayout());

method=new JComboBox(new Object[]{"draw","move","erase",});

add(method);

sbox=new JComboBox(new Object[]{"Pt","Ln","Rect","Cir","Arc",});

add(sbox);

cl=new CLabel[13];

for(int i=0; i<cllength; i++){

cl[i]=new CLabel();

cl[i]addMouseListener(this);

add(cl[i]);

}

fc=new JRadioButton("fc",true);

bc=new JRadioButton("bc");

bg=new ButtonGroup();

bgadd(fc);bgadd(bc);

add(fc);add(bc);

fcsetOpaque(true);

bcsetOpaque(true);

fcsetBackground(Colorwhite);

bcsetBackground(Colorblue);

fillC=new JCheckBox("Fill",true);

drawB=new JCheckBox("Draw",true);

fillCaddActionListener(this);

drawBaddActionListener(this);

add(fillC);add(drawB);

clear=new JButton("clear");

clearaddActionListener(this);

add(clear);

up=new JButton("zUp");

upaddActionListener(this);

add(up);

down=new JButton("zDown");

downaddActionListener(this);

add(down);

save=new JButton("Save");

saveaddActionListener(this);

add(save);

load=new JButton("Load");

loadaddActionListener(this);

add(load);

}

public void mouseClicked(MouseEvent e) {

JLabel l=(JLabel)egetSource();

if(egetClickCount()==2){

Color sc=JColorChoosershowDialog(null, "Color chooser", lgetBackground());

lsetBackground(sc);

mousePressed(e);

}

}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mousePressed(MouseEvent e) {

Color c=((JLabel)egetSource())getBackground();

if(fcisSelected())

fcsetBackground(c);

else if(bcisSelected())

bcsetBackground(c);

Mcp();

}

public void mouseReleased(MouseEvent e) {}

public void actionPerformed(ActionEvent e) {

if(egetSource()==clear)Mclear();

else if(egetSource()==up)Mup();

else if(egetSource()==down)Mdown();

else if(egetSource()==save)Msave();

else if(egetSource()==load)Mload();

else if(egetSource()==fillC||egetSource()==drawB)Mcp();

}

}

class CLabel extends JLabel{

static Color[] cs={Colorred,Colororange,Coloryellow,Colorgreen,Colorcyan,

Colorblue,Colormagenta,Colormagentabrighter(),

Colorwhite,Colorblack,Colorgray,ColorLIGHT_GRAY,ColorDARK_GRAY,};

static int i;

CLabel(){

thissetOpaque(true);

thissetBackground(cs[i++]);

thissetBorder(BorderFactorycreateLineBorder(Colorblack));

thissetPreferredSize(new Dimension(10,20));

}

}

class M{

static JFileChooser jfc=new JFileChooser();

static Menu m=new Menu();

static CVS c=new CVS();

static SA sa=new SA();

static S ts=null,selected=null;

static Color fc,bc;

static void clear(){

sassclear();

crepaint();

}

public static void cp() {

Systemoutprintln(selected);

if(selected!=null){

selectedfillColor=mfcgetBackground();

selectedborderColor=mbcgetBackground();

selectedfc=mfillCisSelected();

selecteddb=mdrawBisSelected();

crepaint();

}

}

public static void up() {

if(selected!=null){

saupZ(selected);

crepaint();

}

}

public static void down(){

if(selected!=null){

sadownZ(selected);

crepaint();

}

}

static{

jfcsetFileFilter(new FileNameExtensionFilter("JDraw file (jdraw,jdr)","jdr","jdraw"));

}

static void save(){

int x=jfcshowSaveDialog(c);

if(x==JFileChooserAPPROVE_OPTION){

File f = jfcgetSelectedFile();

try{

ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(f));

ooswriteObject(sa);

oosflush();

oosclose();

}catch(Exception e){}

}

}

static void load(){

int x=jfcshowOpenDialog(c);

if(x==JFileChooserAPPROVE_OPTION){

File f = jfcgetSelectedFile();

try{

ObjectInputStream oos=new ObjectInputStream(new FileInputStream(f));

Object r=oosreadObject();

if(r!=null){

sa=(SA)r;

crepaint();

}

oosclose();

}catch(Exception e){eprintStackTrace();}

}

}

static int mx,my,tx,ty,ox,oy;

static int pc=0,pmax;

static int sm;

static boolean ne=true;

static int mid;

static void mp(Point p){

mid=mmethodgetSelectedIndex();

if(mid==0){

if(ne){

mx=px;my=py;

pc=0;

sm=msboxgetSelectedIndex();

pmax=sm==42:1;

ne=false;

}

++pc;

}

else if(mid==1){

checkSel(p);

mx=px;my=py;

}

else if(mid==2){

checkSel(p);

if(selected!=null){

sassremove(selected);

crepaint();

}

}

}

private static void checkSel(Point p) {

selected=null;

for(int i=sasssize();i>0; i--)

if(sassget(i-1)shapecontains(p)){

selected=sassget(i-1);break;

}

saselect(selected);

crepaint();

}

static void mt(){

Shape s=null;

int cx,cy,cw,ch;

switch(sm){

case 0:

case 2:

cx=Mathmin(mx,tx);

cy=Mathmin(my,ty);

cw=Mathabs(mx-tx);

ch=Mathabs(my-ty);

if(sm==0)

s=new Ellipse2DDouble(cx,cy,cw,ch);

else

s=new Rectangle(cx,cy,cw,ch);

break;

case 1:

s=new Line2DFloat(mx,my,tx,ty);

break;

case 3:

cw=Mathabs(mx-tx);

ch=Mathabs(my-ty);

int cd=(int)Mathsqrt(Mathpow(mx-tx,2)+Mathpow(my-ty,2))2;

cx=mx-cd/2;

cy=my-cd/2;

s=new Ellipse2DDouble(cx,cy,cd,cd);

break;

case 4:

Path2D p=new Path2DDouble();

pmoveTo(mx,my);

if(pc==1){

plineTo(tx, ty);

}

else{

pquadTo(ox,oy,tx,ty);

}

s=p;

break;

}

ts=new S(s,mfcgetBackground(),mbcgetBackground(),mfillCisSelected(),mdrawBisSelected(),null);

crepaint();

}

static void md(Point p){

if(mid==0){

if(!sassisEmpty()){

sassget(sasssize()-1)sel=false;

}

if(pc>1){

ox=px;oy=py;

}

else{

tx=px;ty=py;

}

mt();

}

else if(mid==1){

if(selected!=null){

moveTo(selected,p);

crepaint();

}

}

else if(mid==2){

checkSel(p);

if(selected!=null){

sassremove(selected);

crepaint();

}

}

}

static void moveTo(S s, Point p) {

if(sshape instanceof Rectangle){

Rectangle r=(Rectangle)sshape;

rsetLocation(rx+px-mx,ry+py-my);

mx=px;my=py;

}

else if(sshape instanceof Ellipse2D){

Ellipse2D e=(Ellipse2D)sshape;

esetFrame(egetX()+px-mx,egetY()+py-my,egetWidth(),egetHeight());

mx=px;my=py;

}

}

static void mr(Point p) {

if(pc==pmax){

pc=0;

ne=true;

saadd(ts);

selected=ts;

ts=null;

}

}

}

class S implements Serializable{

boolean fc,db,sel=true;

Shape shape;

Color fillColor,borderColor;

Stroke stroke;

static Stroke bstroke=new MyBasicStroke();

static Stroke selectStroke=new BasicStroke(1,BasicStrokeCAP_BUTT,BasicStrokeJOIN_MITER,1,new float[]{5,2},1);

S(Shape s,Color c,Color b,boolean f,boolean d,Stroke k){

thisshape=s;thisfillColor=c;thisborderColor=b;thisfc=f;thisdb=d;thisstroke=k==nullbstroke:k;

}

void draw(Graphics2D g){

if(fc){

gsetColor(fillColor);

gfill(shape);

}

if(db){

gsetColor(borderColor);

gsetStroke(stroke);

gdraw(shape);

}

if(sel){

gsetColor(Colorgreen);

gsetStroke(selectStroke);

gdraw(shapegetBounds());

}

}

}

class MyBasicStroke extends BasicStroke implements Serializable{}

class SA implements Serializable{

ArrayList<S> ss=new ArrayList<S>();

void add(S s){

if(s!=null){

for(S sx:ss)

sxsel=false;

ssadd(s);

}

}

S remove(int i){

return ssremove(i);

}

void remove(S s){

ssremove(s);

}

void upZ(S s){

indexZ(s,1);

}

void downZ(S s){

indexZ(s,-1);

}

void indexZ(S s, int i) {

int si=ssindexOf(s);

if(si+i<0||si+i>sssize()-1)return;

swap(s,ssget(si+i));

}

void swap(S a,S b){

int ai=ssindexOf(a);

int bi=ssindexOf(b);

ssset(ai,b);

ssset(bi,a);

}

void select(S s){

for(S x:ss)

xsel=false;

if(s!=null)

ssel=true;

}

void drawAll(Graphics2D g){

for(S s:ss)

sdraw(g);

}

}

以上就是关于Matlab gui 读入图像,程序如下,出现了很畸形的错误,Matlab居然提示了如此多错误error,求破全部的内容,包括:Matlab gui 读入图像,程序如下,出现了很畸形的错误,Matlab居然提示了如此多错误error,求破、matlab GUI-数据输入,输出与处理的简单例子、如何在matlab GUI界面中实现将绘制的图像全屏等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10133596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存