【发布时间】:2018-01-10 22:07:14
【问题描述】:
我正在开发一个插件(用于 Grafana,一个用于分析和监控的开放平台,https://grafana.com/)并且为了使数据分析更容易,我想让插件的用户能够下载一个 .mat 文件直接来自格拉法纳。但是,我无法在我的 JavaScript 代码中创建正确的 .mat 文件。我尝试了以下方法:
<button onclick="download('file text', 'myfilename.mat', 'text/plain')"><a href=""
id="a">click here to download your file</a>Create file</button>
<script>
function download(text, name, type) {
var a = document.getElementById("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
}
</script>
来自JavaScript: Create and save file。但是,以这种方式创建的 .mat 文件会出现错误:
使用加载出错 ASCII 文件 C:\Users\Esmee\Downloads\myfilename (2).mat 的第 1 行上的未知文本 “文件”。
uiimport/runImportdata 中的错误(第 459 行) datastruct = load('-ascii', fileAbsolutePath);
uiimport/gatherFilePreviewData 中的错误(第 427 行) [datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath, type);
uiimport 中的错误(第 244 行) 收集文件预览数据(文件绝对路径);
我不知道该怎么办。我认为问题在于简单地将字符串“文件文本”放在 .mat 文件中不是 MATLAB 通常使用的文件语法。有没有人有使用 Javascript/html 创建 .mat 文件的经验,或者有人知道这个文件应该以什么格式制作以便在 MATLAB 中可读?
提前致谢!
【问题讨论】:
-
附带说明:MATLAB 可以读取比 .mat 更多的内容。您是否考虑过以其他方式存储数据?
-
你可以用python来save mat-files。也许这会有所帮助。
标签: javascript html matlab export