Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Trouble running MATLAB code
Date: Sun, 5 Oct 2008 00:26:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 121
Message-ID: <gc91iq$fq8$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1223166362 16200 172.30.248.35 (5 Oct 2008 00:26:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 5 Oct 2008 00:26:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1528031
Xref: news.mathworks.com comp.soft-sys.matlab:493661


Hi,

I'm having trouble with my code. 
This is what my code does: It detects analog inputs from my DATA acquisition device (USB-1208FS), which in this case is some voltage readings, and then evaluates and outputs a specific voltage. I keep getting the error "Invalid Count" when I run the program.

Here's the code: 
%Create an analog input "ai" and analog output "ao" with ID 0
ai = analoginput('mcc',0);
addchannel(ai,0:1);
ao = analogoutput('mcc',0);
addchannel(ao,0:1);


%Define duration to every 1 ms
duration = 0.001;
%Set the sample rate to 1000 Hz
set(ai,'SampleRate',1000)
%Acquire rate from the input
ActualRate = get(ai,'SampleRate');
%Define the amount of samples to acquire PER trigger
set(ai,'SamplesPerTrigger',ActualRate*duration)

%Set the Trigger to repeat an infinite number of times
set(ai,'TriggerRepeat',0);
set(ao,'RepeatOutput',0);


control_variable = 1;

while( control_variable==1 )

start(ai);
wait(ai,1);
    
    vin = peekdata(ai,1);

    if (vin(1,1)>=3.00 && vin(1,1)<=3.19)
    putdata(ao,[0.40 0.00]);
        
    elseif (vin(1,1)>=3.20 && vin(1,1)<=3.39)
    putdata(ao,[0.80 0.00]);
            
    elseif (vin(1,1)>=3.40 && vin(1,1)<=3.59)
    putdata(ao,[1.20 0.00]);
            
    elseif (vin(1,1)>=3.60 && vin(1,1)<=3.79)
    putdata(ao,[1.50 0.00]);
            
    elseif (vin(1,1)>=3.80 && vin(1,1)<=3.99)
    putdata(ao,[1.80 0.00]);
            
    elseif (vin(1,1)>=4.00 && vin(1,1)<=4.19)
    putdata(ao,[2.10 0.00]);
            
    elseif (vin(1,1)>=4.20 && vin(1,1)<=4.39)
    putdata(ao,[2.50 0.00]);
            
    elseif (vin(1,1)>=4.40 && vin(1,1)<=4.59)
    putdata(ao,[2.90 0.00]);
        
    elseif (vin(1,1)>=4.60 && vin(1,1)<=4.79)
    putdata(ao,[3.30 0.00]);
        
    elseif (vin(1,1)>=4.80 && vin(1,1)<=5.00)
    putdata(ao,[4.00 0.00]);
            
    else
    putdata(ao,[0.00 0.00]);
    
    end;
            
    if (vin(1,2)>=3.00 && vin(1,2)<=3.19)
    putdata(ao,[0.00 0.40]);
        
    elseif (vin(1,2)>=3.20 && vin(1,2)<=3.39)
    putdata(ao,[0.00 0.80]);
            
    elseif (vin(1,2)>=3.40 && vin(1,2)<=3.59)
    putdata(ao,[0.00 1.20]);
            
    elseif (vin(1,2)>=3.60 && vin(1,2)<=3.79)
    putdata(ao,[0.00 1.50]);
            
    elseif (vin(1,2)>=3.80 && vin(1,2)<=3.99)
    putdata(ao,[0.00 1.80]);
            
    elseif (vin(1,2)>=4.00 && vin(1,2)<=4.19)
    putdata(ao,[0.00 2.10]);
            
    elseif (vin(1,2)>=4.20 && vin(1,2)<=4.39)
    putdata(ao,[0.00 2.50]);
            
    elseif (vin(1,2)>=4.40 && vin(1,2)<=4.59)
    putdata(ao,[0.00 2.90]);
        
    elseif (vin(1,2)>=4.60 && vin(1,2)<=4.79)
    putdata(ao,[0.00 3.30]);
        
    elseif (vin(1,2)>=4.80 && vin(1,2)<=5.00)
    putdata(ao,[0.00 4.00]);
            
    else
    putdata(ao,[0.00 0.00]);
    
    end;
    
stop(ai);

start(ao);
pause(0.001);
stop(ao);

end;

stop(ai);
delete(ai);


Any help will be appreciated. Btw, is there an easier way to make the if and elseif statements without writing all that in?

Thanks