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
darova
darova 2020 年 3 月 28 日
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 ExchangeDigital 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