TeX - LaTeX Asked on December 13, 2021
I am using pgfplots
to create figures, and I have a (large) set of simulation data generated from Matlab
. It is in the .mat
format. The data are of the form (two column)
(1,0.2)
(1,0.3)
...
(1,0.2)
...
(2,0.4)
(2,0.1)
...
A scatter plot in pgfplots
would be appropriate. I want to directly importing this file using pgfplots
. Unfortunately, the following code seems not work.
documentclass{article}
usepackage{pgfplots}
usepackage{xcolor}
begin{document}
begin{figure}
centering
begin{tikzpicture}
begin{axis}
addplot+[scatter]
table{test.mat};
end{axis}
end{tikzpicture}
end{figure}
end{document}
Is there anyone know how to import these data ? Since the size is a little bit large, it is not possible to copy every sample into the code.
In newer Matlab versions, the recommended way is to generate a table from the array and write the table to a CSV file. The table has a header row that contains the column names and is also written to the CSV. See MATLAB Answers
Answered by smarties on December 13, 2021
This is due to the fact that .mat
file is a binary format and TeX can't read binary. I don't know how it can be made possible to read binary format from a file but a rather more convenient way is to store the arrays in a tall matrix as columns.
Suppose you have the data columns a,b,c with equal length (otherwise pad the missing entries with NaN or Inf such that pgfplots can discard it). This can be done in matlab via
Mymatrix = [a b c];
save('myfile.txt', 'Mymatrix', '-ascii','-double');
This would save the arrays in a plain text format with no headers. I didn't check if full path is supported in the file name field but should be possible.
In general, I would recommend staying away from including column names to the Mymatrix
. Because matlab is a great software.
Answered by percusse on December 13, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP