数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 3042|回复: 2

关于VB与MATLAB的连接问题(请指教)

[复制链接]
发表于 2004-4-27 20:49:08 | 显示全部楼层 |阅读模式
<>我想在VB调用一个switch语句总是不成功
程序如下:
VB:
Private Sub Command1_Click()
Dim x, y As Single
Dim sa As aaaab.aaaab
Set sa = New aaaab.aaaab
x = InputBox("x")
k = 1
Call sa.aabc(1, y, x)
Print x
Print y
End Sub
Option Explicit
Global k
\\\\\\\\\\\\\\\\\\\
m-file
function y=aabc
global k;
switch k
case 1
y=x+2;
case 2
y=2*x;
case 3
y=x^2;
end
\\\\\\\\\\\\\\\\\\
我是用combuild把aabc.m做成.dll
再在VB中调用
运行出错了:
Run-time error '-214767259(80004005)':
SWITCH expression must be a scalar or string constant
\\\\\\\\\\\\\\\\\\\\
请教怎么改才能传递过去??
</P>
发表于 2004-4-28 05:41:38 | 显示全部楼层
<>function mmouse(cmd, handles)
global waves</P><>hf = handles.mcut;
hw = handles.axes_wave;</P><>ud = get(hf,'userdata');</P><P>% GUI not started
if isempty(ud)
    return
end</P><P>% make sure the mouse is above the wave
pos = get(hw,'position');
pt  = get(hf,'currentpoint');
if pt(1)&lt;pos(1) | pt(1)&gt;pos(1)+pos(3) | pt(2)&lt;pos(2) | pt(2)&gt;pos(2)+pos(4)
    setptr(hf, 'arrow');
    return
end</P><P>% find the current point of the mouse over the wave
pt = get(hw,'currentpoint');
pt = fix(pt(1));
pt = max(pt,1);
pt = min(pt,length(ud.wave));</P><P>% find the current xlim and x-range
xlim = get(hw, 'XLim');
xlen = xlim(2)-xlim(1);</P><P>switch cmd
case 'down'
    % mouse down
    if abs(ud.x1 - pt)/xlen &lt; 0.02
        ud.drag = 1;
    elseif abs(ud.x2 - pt)/xlen &lt; 0.02
        ud.drag = 2;
    else
        ud.drag = 3;
        ud.x0 = pt;
    end
    setptr(hf, 'closedhand');</P><P>case 'motion'
    % mouse is moving
    switch ud.drag
    case 0
        %fprintf('%d %d %d\n', ud.x1, ud.x2, fix(pt))
        if abs(ud.x1 - pt)/xlen &lt; 0.02
            setptr(hf, 'hand1');
        elseif abs(ud.x2 - pt)/xlen &lt; 0.02
            setptr(hf, 'hand2');
        else
            setptr(hf, 'glass');
        end</P><P>    case 1
        % dragging start line
        set(ud.h1, 'Xdata', [pt pt]);
        ud.x1 = pt;</P><P>    case 2
        % dragging end line
        set(ud.h2, 'Xdata', [pt pt]);
        ud.x2 = pt;</P><P>    case {3,4}
        % dragging the whole wave
        xlim = xlim + (ud.x0 - pt);
        set(hw, 'XLim', xlim);
        % yes, it was dragged
        ud.drag = 4;
        
    end</P><P>case 'up'
    % mouse is up
    if ud.drag == 3
        ud.drag = 0;
    end</P><P>    if ud.drag == 0
        %zoom
        m = get(hf,'SelectionType');
        if strcmp(m,'normal') == 1
            %zoom in
            xlim = [fix((xlim(1)+pt)/2) fix((xlim(2)+pt)/2)];
            set(hw, 'XLim', xlim);
        elseif strcmp(m,'alt') == 1
            %zoom out
            xlim = [2*xlim(1)-pt 2*xlim(2)-pt];
            xlim(1) = max(xlim(1),1);
            xlim(2) = min(xlim(2),length(ud.wave));
            set(hw, 'XLim', xlim);
        end
    end</P><P>    setptr(hf, 'glass');
    ud.drag = 0;
    ud.x0   = 0;</P><P>    waves(ud.index).x1 = ud.x1;
    waves(ud.index).x2 = ud.x2;
   
end</P><P>% modify the userdata
set(hf,'userdata', ud);
</P>
 楼主| 发表于 2004-4-28 06:08:18 | 显示全部楼层
看不怎么懂能解释一下么
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-27 06:25 , Processed in 0.092185 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表