how to write arrays directly to the base workspace from the app designer based on data collected using the data acquisition toolbox?
6 次查看(过去 30 天)
显示 更早的评论
I have been having trouble collecting data then saving using the live data acquistion example. Since I have tried to use the assignin & evalin functions to write variables directly into the base workspace but I am having difficulties accomplishing this. I saw some things about simulink but they did not make much sense to me. Does anyone know what I might need to do? I know I might need to make the variables public but I'm not to sure where to start.
All I am trying to write is one variables that contains timestamps and multiple channels worth of data collected using the data acqusition toolbox.
Thanks!
0 个评论
采纳的回答
Ayush Singh
2024-3-4
Hi Connor
To manage the task of collecting data and then saving it, especially when using the Data Acquisition Toolbox in MATLAB, you can focus on MATLAB's capabilities which are suffice for most data acquisition and logging needs. The process involves setting up your data acquisition session, collecting data, and then saving this data to the MATLAB base workspace or directly to a file.
Here's a simplified approach to handle this:
1.Set Up Data Acquisition
First, ensure you have the necessary hardware support package installed for your data acquisition device. Then, you can set up your data acquisition session. For example, using a National Instruments device:
d = daq.createSession('ni');
addAnalogInputChannel(d, 'Dev1', 0, 'Voltage');
2. Collect Data
To collect data, you can use the `startForeground` function for synchronous operations or `startBackground` for asynchronous operations. Here's an example of collecting data synchronously:
[data, timestamps] = startForeground(d);
This command will block MATLAB execution until all data is collected. `data` will contain the collected data, and `timestamps` will contain the corresponding timestamps.
3. Saving Data to Base Workspace
If you want to save the `data` and `timestamps` directly to the MATLAB base workspace, you can use the `assignin` function:
assignin('base', 'collectedData', data);
assignin('base', 'collectedTimestamps', timestamps);
This will create variables `collectedData` and `collectedTimestamps` in the base workspace.
4. Making Variables Accessible
Since you mentioned making variables public, if you're working within a function or script and you want these variables to be accessible from the base workspace or other functions, using `assignin` as shown above is the correct approach.
Hope it helps!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 National Instruments Frame Grabbers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!