Nested for loops using vectorization in MATLAB

14 vues (au cours des 30 derniers jours)
Ahmad Lakhani
Ahmad Lakhani le 22 Sep 2017
Modifié(e) : Ahmad Lakhani le 22 Sep 2017
I currently have two national instrument devices hooked up to MATLAB and have this nested for loop:
for i=1: 5
removeChannel(session, 7)
addAnalogInputChannel(session, 'cDAQ1Mod8', ['ai' num2str(i)], 'Voltage');
for j=1: 5
signal = [in(i,:) out(j,:)];
outputSingleScan(session, signal);
measurements(6-j,6-i) = session.inputSingleScan;
end
end
Basically what this does is removes the last channel in the session and adds a new one from the DAQ depending on the iteration. A signal is then sent from the NI USB device and then another measurement is read from the DAQ. How do I use vectorization for this nested for loop?
  3 commentaires
Ahmad Lakhani
Ahmad Lakhani le 22 Sep 2017
Modifié(e) : Ahmad Lakhani le 22 Sep 2017
@DonaldLee outputSingleScan is a Matlab function. the first argument is the session and the second argument it takes is a row vector. The function takes the voltage measurement from the DAQ.
Yeah I need it vectorized because it is too slow. My goal here is to see whether or not it makes a difference for my code. Thanks for the help with the if statements.
OCDER
OCDER le 22 Sep 2017
Oh, I see. I don't have the Data Acquisition Toolbox, so hopefully one of the pros will stop by to lend a help. Also, feel free to edit the question with the simpler code to make it easy on their eyes :)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Instrument Control Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by