Nested for loops using vectorization in MATLAB
Mostra commenti meno recenti
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 Commenti
Not sure how to vectorize this (don't have the toolbox), but you could simplify the code like this if you want:
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
Also, are you trying to vectorize this because this is too slow? You would have to determine what the bottle neck is first. For instance, even if we could vectorize this, if removeChannel or outputSingleScan is slow, then vectorizing may not help much.
Ahmad Lakhani
il 22 Set 2017
Modificato: Ahmad Lakhani
il 22 Set 2017
OCDER
il 22 Set 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 :)
Risposte (0)
Categorie
Scopri di più su Instrument Control Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!