Clear Filters
Clear Filters

How do I convert a CSV into a .mat file?

136 views (last 30 days)
Hi all! I'm very, very new to Matlab.
With that said, does anyone know how to convert a CSV file into a .mat file in the MATLAB environment? I've had a lot of trouble answering this question.
I attached a CSV file I'd like to convert as an example.
Thank you!
  1 Comment
Stephen23
Stephen23 on 13 Feb 2023
"I've had a lot of trouble answering this question."
Use READMATRIX and SAVE. If you don't know what options you have for file import/export, start here:

Sign in to comment.

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 13 Feb 2023
Since the csv only contains numeric data, use readmatrix to load the data in a variable
variablename=readmatrix('s1.csv')
variablename = 601×30
1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000 21.0000 22.0000 23.0000 24.0000 25.0000 26.0000 27.0000 28.0000 29.0000 30.0000 -1.3058 0.4753 0.2386 0.8905 0.1900 -0.1847 1.2578 0.4223 -0.0882 -0.7741 0.5463 0.1825 0.5501 0.5588 -0.2791 0.9483 1.3789 -0.6153 -1.1911 -2.2146 0.4179 -0.6850 -0.5301 2.4541 -0.2703 2.0393 -0.4873 0.6449 1.1344 -2.0657 0.6919 0.9040 0.9583 -0.6240 0.6435 0.0130 0.9942 -0.7210 1.0510 -0.2517 -0.2882 0.3563 0.9735 0.8418 -0.9255 -0.0538 -0.5877 -0.7887 0.7637 1.0477 -0.3909 -1.0357 0.4721 0.6661 -0.3275 -1.2818 0.7658 2.4698 -1.1613 1.1347 0.7997 -0.8532 0.2305 -0.1190 -0.2123 -0.0162 0.7013 -0.3525 -0.1148 -0.7534 -0.1055 -0.3013 -1.1287 -0.6971 0.2363 2.7745 0.1054 0.0470 -0.8231 0.8944 0.4056 1.9781 0.2339 0.1322 -0.7304 1.1916 0.4047 0.4114 0.8753 0.6590 -2.4909 0.4026 0.4192 0.4730 0.0149 0.6116 -0.3198 -1.2283 0.0982 0.7751 -0.5547 1.6765 -0.1421 0.1224 1.1226 -0.3533 -0.4501 0.6416 0.7636 -1.8042 0.3936 -0.6506 0.4042 -0.0965 0.3386 -0.6428 -0.7394 -0.7689 -0.1163 -0.6049 0.6712 0.0594 0.6565 -0.9345 0.2206 -0.2595 -1.5355 1.4188 0.0184 -0.0844 -0.6431 -1.2969 0.1613 0.4944 0.6865 -0.2415 -0.2418 0.6777 -0.6915 0.8652 -1.6952 -0.0834 -0.7070 -1.5196 0.3596 0.6885 0.3269 0.6826 0.0505 0.5837 0.7416 -0.2559 -1.3103 0.5226 -1.2307 0.9265 -1.0310 -1.3979 0.3473 -0.5073 0.7573 -0.3558 -0.8489 -0.9468 -1.2723 -1.4913 0.1615 -0.7566 -0.8487 1.1302 -0.5367 2.1766 1.1139 -0.4200 -1.3210 -0.9183 1.2579 -2.0190 -1.5843 0.0366 -1.8363 0.0953 -0.1014 -1.5904 0.5274 -1.8288 0.6184 0.3599 0.0473 0.9205 0.1349 0.2421 -0.6110 0.2096 -1.5279 -0.6166 0.9268 0.4973 -0.4492 -0.0835 -0.1561 -0.5549 -1.2751 -0.7055 -0.3526 1.4965 -1.0777 0.5511 1.0568 1.1883 0.4999 -0.3426 0.4156 2.3611 0.2794 -0.0015 -0.2282 0.8923 0.1668 0.3200 -0.9493 -0.1182 0.5362 1.1284 1.0759 -0.7482 -0.9277 -0.6424 -0.5670 1.2100 -0.6835 -0.0577 -0.3288 -0.8385 0.3540 -0.2467 1.7741 -1.7797 -0.7689 -0.1242 0.6074 -0.9442 -1.5507 -1.3478 -0.4522 0.4705 -0.8007 -1.2068 -1.2416 0.6148 -0.3209 0.2555 0.7224 0.8626 -0.2047 -1.6995 0.1350 1.1163 0.4736 0.5631 -0.4381 0.2127 1.1229 0.7547 -0.0553 0.4967 1.3056 -0.8450 1.0019 -0.6653
and save accordingly
save('filename.mat','variablename')

More Answers (1)

Arif Hoq
Arif Hoq on 13 Feb 2023
use Readtable function or readmatrix if your data includes numeric
loadyourfile=readtable("s1.csv");
save('yourmatfile.mat','loadyourfile')

Categories

Find more on Search Path in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!