Looping data acqusition process for 100 cycles

The following is a code to acquire data from a tri-axial acclerometer and log the data into excel file. I need help in looping this code for 100 Cycles.
daq.getDevices
daqSession = daq.createSession('ni')
daqSession.addAnalogInputChannel('Dev1', 'ai0', 'Accelerometer');
daqSession.addAnalogInputChannel('Dev1', 'ai1', 'Accelerometer');
daqSession.addAnalogInputChannel('Dev1', 'ai2', 'Accelerometer');
daqSession.Rate = 2048;
daqSession.DurationInSeconds = 5;
daqSession.Channels(1).Sensitivity = 0.010;
daqSession.Channels(2).Sensitivity = 0.010;
daqSession.Channels(3).Sensitivity = 0.010;
[data,time] =daqSession.startForeground();
A=[data, time];
filename ='Condition-1.xlsx';
xlswrite(filename,A)
daqSession.release();
delete(daqSession);
clear daqSession;
x=data(:,1);y=data(:,2);z=data(:,3);
figure
plot(time,x,time,y,time,z)
title('Time domain signal')
xlabel('t (seconds)')
ylabel('X(t)')

 채택된 답변

darova
darova 2020년 3월 25일

1 개 추천

Simple example of for loop work
for i = 1:5
i
end

댓글 수: 4

syed
syed 2020년 3월 28일
have i understood right?
for i=1:5
daq.getDevices
daqSession = daq.createSession('ni')
daqSession.addAnalogInputChannel('Dev1', 'ai0', 'Accelerometer');
daqSession.addAnalogInputChannel('Dev1', 'ai1', 'Accelerometer');
daqSession.addAnalogInputChannel('Dev1', 'ai2', 'Accelerometer');
daqSession.Rate = 2048;
daqSession.DurationInSeconds = 5;
daqSession.Channels(1).Sensitivity = 0.010;
daqSession.Channels(2).Sensitivity = 0.010;
daqSession.Channels(3).Sensitivity = 0.010;
[data,time] =daqSession.startForeground();
A=[data, time];
filename ='Condition-i.xlsx';
xlswrite(filename,A)
daqSession.release();
delete(daqSession);
clear daqSession;
x=data(:,1);y=data(:,2);z=data(:,3);
figure
plot(time,x,time,y,time,z)
title('Time domain signal')
xlabel('t (seconds)')
ylabel('X(t)')
end
Change filename variable
% filename ='Condition-i.xlsx';
filename = ['Condition-' num2str(i) '.xlsx'];
% filename = sprintf('Condition-%d.xlsx',i); % or this
syed
syed 2020년 3월 28일
Thank you very much. Now my code is automated :)
darova
darova 2020년 3월 28일
you are welcome

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Digital Input and Output에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2020년 3월 25일

댓글:

2020년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by