API 下载日志文件并转换 | MATLAB
记录并下载.li 文件
要流式传输到文件(在单个脚本内记录和转换)而不是记录到文件,请参阅本文:
API 流和 stream_to_file | MATLAB
首先,启动日志记录会话并下载文件。有关 API 的更多详细信息,请访问我们的 API 参考:
数据记录器| API 参考download_file MATLAB 数据记录器示例
% moku example: Basic Datalogger
% (c) 2025 Liquid Pty. Ltd.
%% Connect to your Moku
i = MokuDatalogger('192.168.###.###');
try
% Set-up the Datalogger
i.set_acquisition_mode('mode','Precision');
i.set_samplerate(1e3);
i.generate_waveform(1, 'Sine', 'amplitude',1, 'frequency',10e3);
% Start the data logging session
logging_request = i.start_logging('duration',10);
log_file = logging_request.file_name;
location = logging_request.location;
% Set up to display the logging process
progress = i.logging_progress();
while progress.complete < 1
fprintf('%d seconds remaining \n',progress.time_remaining)
pause(1);
progress = i.logging_progress();
end
% Download the log file from the Moku to current directory
i.download_file(location, log_file, log_file);
fprintf('Downloaded log file to local directory. %s\n', log_file)
catch ME
% End the current connection session with your Moku
i.relinquish_ownership();
rethrow(ME)
end
% End the current connection session with your Moku
i.relinquish_ownership();
示例输出:
9 seconds remaining
...
0 seconds remaining
File downloaded successfully!
Downloaded log file to local directory. MokuDataLoggerData_20250116_131731.li
Moku CLI 方法
确保您已安装 mokucli,您可以从实用程序页面下载它。
您可以从 MATLAB 命令窗口转换为所需的文件类型:csv、npy、mat 或 hdf5。在本例中,我们将转换为 .mat。
>> ! mokucli convert MokuDataLoggerData_20250116_131731.li --format=mat
[===========================================================================]
Done.
另一种方法是从脚本内部调用 mokucli,理想情况下,在这种用例中,将使用streaming
和stream_to_file
,请参阅此文章:
API 流和 stream_to_file | MATLAB
从脚本内部调用 mokucli 不是最佳实践,但它可以作为一种选择:
command = ['mokucli convert --format=mat ' log_file];
system(command,'-echo');
file_name = [log_file(1:end-2), 'mat'];
LI 文件转换器方法
或者,你也可以使用 LI 文件转换器 GUI 转换文件,可以从Moku :应用程序访问或从实用程序页面下载

您可以选择文件类型,然后将文件拖放到转换器,或者使用“文件 | 打开文件”或“Ctrl/Cmd + O”从转换器打开文件

从文件加载数据
然后,您可以使用转换后的文件来加载和分析数据,并调整file_name
和channels
参数以匹配您的实验。
file_name = 'MokuDataLoggerData_20250116_131731.mat';
channels = 2;
disp(file_name);
if ~isfile(file_name)
error('Convert failed, no file received');
end
data = struct('time', [], 'ch1', []);
file = load(file_name);
data.time = file.moku.data(:, 1);
for i = 1:channels
data.(['ch', num2str(i)]) = file.moku.data(:, i+1);
end
keys = fieldnames(data);
for k = 1:numel(keys)
key = keys{k};
disp([key, ': ', mat2str(data.(key)(1:3)), ' ... [', num2str(data.(key)(end)), ']']);
end
fig = figure('Position', [100, 100, 1000, 300]);
hold on;
for i = 1:channels
plot(data.time, data.(['ch', num2str(i)]), 'DisplayName', ['Channel ', num2str(i)]);
end
title('Logged Data');
grid on;
xlabel('Time (s)');
ylabel('Voltage (V)');
legend show;
hold off;
示例输出:
MokuDataLoggerData_20250116_131731.mat
time: [0;0.001;0.002] ... [9.999]
ch1: [0.00137754767956721;0.00140193458810245;0.00135472403439962] ... [0.0011665]
ch2: [0.0156492042681293;0.0155779194585648;0.0155710410997472] ... [0.015813]
