I am developing a plug-in (for Grafana,an open platform for analytics and monitoring, https://grafana.com/) and to make data analysis easier, I want to enable the user of the plug-in to download a .mat file directly from Grafana. However, I am not able to create a proper .mat file in my JavaScript code. I have tried the following:
<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>
From JavaScript: Create and save file. However, the .mat file that is created this way gives the errors:
Error using load Unknown text on line number 1 of ASCII file C:\Users\Esmee\Downloads\myfilename (2).mat "file".
Error in uiimport/runImportdata (line 459) datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 427) [datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath, type);
Error in uiimport (line 244) gatherFilePreviewData(fileAbsolutePath);
I have no idea what to do with this. I think the problem is that simply putting the string 'file text' in a .mat file is not the file syntax that MATLAB normally uses. Does anyone have experience with creating a .mat file with Javascript/html, or does someone know in what format this file should be made in order to be readable in MATLAB?
Thanks in advance!