簡體   English   中英

使用JavaScript創建.mat文件

[英]use JavaScript to create a .mat file

我正在開發一個插件(用於Grafana,一個用於分析和監視的開放平台, https: //grafana.com/),並且為了簡化數據分析,我希望允許該插件的用戶下載。 Mat文件直接來自Grafana。 但是,我無法在我的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:創建並保存文件 但是,以這種方式創建的.mat文件會出現錯誤:

在ASCII文件C:\\ Users \\ Esmee \\ Downloads \\ myfilename(2).mat“ file”的第1行上使用加載未知文本時出錯。

uiimport / runImportdata(第459行)中的錯誤datastruct = load('-ascii',fileAbsolutePath);

uiimport / gatherFilePreviewData中的錯誤(第427行)[datastruct,textDelimiter,headerLines] = runImportdata(fileAbsolutePath,type);

uiimport中的錯誤(第244行)collectFilePreviewData(fileAbsolutePath);

我不知道該怎么辦。 我認為問題在於,僅將字符串“文件文本”放入.mat文件中並不是MATLAB通常使用的文件語法。 有沒有人有使用Javascript / html創建.mat文件的經驗,還是有人知道該文件應采用哪種格式才能在MATLAB中可讀?

提前致謝!

MAT文件以二進制形式存儲日期。

MathWorks 在這里發布了文件格式規范。

您可以嘗試在單個Uint8Array中格式化數據(按照規范)並將其傳遞給Blob構造函數 有關更多詳細信息,請參見對此問題的接受答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM