CSV To MATLAB Array

Login

Email
Password

Don't have an account yet?

Go to Sign up

{{ workbook ? 'Online Table Editor' : 'Input Data' }}
Change File Enter Data
Row Col Row Col
Transpose Clear Delete Empty Deduplicate
ABC abc Abc
Replace
First Row as Header
{{ displayRows.length }} rows x {{ displayHeaders.length }} columns{{ firstRowAsHeader ? ' (1 header)' : '' }} {{ selectedRows.length > 0 ? selectedRows.length + ' selected' : '' }}
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert CSV to MATLAB online — paste, edit, and download MATLAB.

Convert Restart
Insert Row Below
Insert Row Above
Insert Column Right
Insert Column Left
Delete Row {{ contextMenu.row + 1 }}
Delete Column {{ contextMenu.col + 1 }}
Clear Cell
Clear Row
Case sensitive Use regex Cancel Replace All

CSV to MATLAB Array — Free Online MATLAB Code Generator

What Is MATLAB?

MATLAB (Matrix Laboratory) is a programming platform for numerical computing, signal processing, control systems, and data analysis. It is widely used in engineering, physics, finance, and academia.

>> x = [1, 2, 3, 4, 5];

>> mean(x)

ans = 3

MATLAB Array Types

Numeric Matrix

A 2D array of numbers. All elements must be numeric.

A = [1, 2, 3; 4, 5, 6; 7, 8, 9];

% Access

A(1, 2)    % = 2

A(:, 1)    % = [1; 4; 7]

size(A)    % = [3, 3]

Cell Array

A container where each cell can hold any data type. Ideal for mixed-type tabular data from CSV.

C = {'Alice', 30, 'New York'; 'Bob', 25, 'London'; 'Charlie', 35, 'Tokyo'};

% Access with curly braces for content

C{1, 1}    % = 'Alice'

C{2, 3}    % = 'London'

Struct Array

An array of structures with named fields.

S(1).name = 'Alice';

S(1).age = 30;

S(1).city = 'New York';


S(2).name = 'Bob';

S(2).age = 25;

S(2).city = 'London';

Table

A tabular data structure with column names — closest to a spreadsheet.

T = table(...

{'Alice'; 'Bob'; 'Charlie'}, ...

[30; 25; 35], ...

{'New York'; 'London'; 'Tokyo'}, ...

'VariableNames', {'name', 'age', 'city'});


% Access

T.name     % column as array

T{1, 2}    % cell access

T.age > 28 % logical indexing

When to Use Each Type

TypeBest ForMixed TypesNamed Columns
MatrixPure numeric dataNoNo
Cell arrayMixed data, quick prototypingYesNo
Struct arrayRecord-style data with named fieldsYesYes (field names)
TableSpreadsheet-like data, analysisYesYes

readmatrix() / readcell() / readtable() vs. This Tool

Using readmatrix() (Runtime — Numeric Data)

A = readmatrix('data.csv');

Using readcell() (Runtime — Mixed Data)

C = readcell('data.csv');

Using readtable() (Runtime — Table with Headers)

T = readtable('data.csv');
Aspectreadmatrix/readcell/readtable
When to useDynamic CSV files at runtime
RequiresFile path at runtime
FlexibilityHandles any CSV
DependenciesCSV file must be present

Using This Tool (Code Generation)

AspectThis Tool
When to useStatic data, testing, homework, prototypes
OutputSelf-contained MATLAB code
FlexibilityEditable MATLAB source
DependenciesNone at runtime — data is literal code

Why Convert CSV to MATLAB Code?

Use CaseDescription
HomeworkEmbed sample datasets directly in MATLAB scripts
TestingCreate test arrays for unit tests
Signal processingHardcode sensor data as MATLAB arrays
PrototypingTest algorithms with real data without file I/O
MATLAB Live ScriptsInclude data inline in .mlx documents
Simulink modelsDefine lookup table data in model callbacks
PresentationsShare self-contained MATLAB demos
Data cleaningUse the table editor to clean CSV before generating code
Control systemsDefine plant model parameters from experimental CSV data
Machine learningHardcode training/test splits for reproducibility

Core Features

1. Online Table Editor

After loading CSV data, an interactive spreadsheet grid lets you edit before converting:

OperationDescription
Undo / RedoFull edit history support
Add Row / ColumnInsert new rows and columns
Delete SelectedRemove selected rows or columns
TransposeSwap rows and columns
ClearRemove all data
Delete EmptyRemove empty rows/columns
DeduplicateRemove duplicate rows
ReplaceFind and replace (with regex support)
Case transformUPPERCASE, lowercase, Title Case
Insert/deleteRight-click for row/column operations
First Row as HeaderToggle header treatment
Keyboard navigationArrow keys, Tab, Enter for cell navigation

2. Privacy by Design

All processing runs entirely in your browser. No CSV data is uploaded to any server.

How to Use

Step 1: Load CSV Data

Choose one of two input methods:

  • Upload a file: Drag a .csv or .tsv file onto the upload area, or click to browse.

  • Paste data: Click "Enter Data" to switch to the code editor. Paste your CSV.

Step 2: Edit in Table Editor (Optional)

Use the toolbar to clean your data before converting.

Step 3: Enable "First Row as Header" (Optional)

Toggle ON if the first row contains column headers.

Step 4: Convert

Click Convert. The MATLAB code appears in the "Output Data" panel.

Step 5: Copy or Download

  • Click Copy to Clipboard to paste into your .m file.

  • Premium users can click Download File to save.

Complete Example — Sensor Data

Input CSV:

sensor_id,temperature,humidity,pressure

SENS-01,22.5,45.2,1013.25

SENS-02,18.3,62.1,1015.50

SENS-03,25.0,38.7,1012.00

SENS-04,20.1,55.3,1014.75

Output (Cell Array):

data = {

   'SENS-01', 22.5, 45.2, 1013.25;

   'SENS-02', 18.3, 62.1, 1015.50;

   'SENS-03', 25.0, 38.7, 1012.00;

   'SENS-04', 20.1, 55.3, 1014.75;

};

Example — Pure Numeric Data (Matrix)

Input CSV:

1.0,2.0,3.04.0,5.0,6.07.0,8.0,9.0

Output:

data = [1.0, 2.0, 3.0; 4.0, 5.0, 6.0; 7.0, 8.0, 9.0];

Example — Student Grades

Input CSV:

Name,Math,Physics,Chemistry

Alice,92,88,95

Bob,78,82,71

Charlie,95,91,89

Diana,88,76,93

Output:

data = {

   'Alice', 92, 88, 95;

   'Bob', 78, 82, 71;

   'Charlie', 95, 91, 89;

   'Diana', 88, 76, 93;

};

Working with the Generated Array

Common Cell Array Operations

% Access

data{1, 1}          % First cell content

data(1, :)          % First row as cell array

data(:, 2)          % Second column as cell array


% Extract numeric column

temps = [data{:, 2}]    % Vertical concatenation to vector

mean(temps)              % Average temperature


% Filter

idx = cellfun(@(x) x > 20, [data{:, 2}]);

hot_sensors = data(idx, :);


% Convert to matrix (numeric columns only)

numeric_cols = cell2mat(data(:, 2:4));

Convert Cell Array to Table

T = cell2table(data, 'VariableNames', ...

   {'sensor_id', 'temperature', 'humidity', 'pressure'});

Convert to Struct Array

[nrows, ~] = size(data);

for i = 1:nrows

   S(i).sensor_id = data{i, 1};

   S(i).temperature = data{i, 2};

   S(i).humidity = data{i, 3};

   S(i).pressure = data{i, 4};

end

MATLAB Matrix vs Cell Array Syntax

FeatureMatrix []Cell Array {}
DeclarationA = [1, 2; 3, 4]C = {'a', 1; 'b', 2}
Row separator;;
Column separator, or space, or space
Element accessA(1,2)C{1,2}
Type constraintAll numericAny type per cell
Best forNumbers, mathMixed data, strings

CSV-to-MATLAB Value Mapping

CSV ValueMATLAB OutputExample
42Numeric42
3.14Numeric3.14
helloString'hello'
trueString'true'
Empty cellEmpty string''

MATLAB Quick Reference for Array Operations

FunctionPurposeExample
size(A)Dimensionssize(A)[3, 4]
length(A)Longest dimensionlength(A)4
numel(A)Total elementsnumel(A)12
A(i, j)Matrix indexA(2, 3)
C{i, j}Cell contentC{1, 2}
A(:, k)k-th columnA(:, 1)
A(k, :)k-th rowA(1, :)
A'TransposeA'
reshape(A, m, n)Reshapereshape(A, 2, 6)
sort(A)Sortsort(A)
max(A)Maximummax(A)
min(A)Minimummin(A)
mean(A)Meanmean(A)
sum(A)Sumsum(A)
find(A > 0)Find indicesfind(A > 0)
cell2mat(C)Cell to matrixcell2mat(C)
cell2table(C)Cell to tablecell2table(C)
num2str(n)Number to stringnum2str(42)
str2num(s)String to numberstr2num('42')
disp(A)Displaydisp(A)

MATLAB in Industry

FieldUse Case
Signal processingFilter design, FFT, spectral analysis
Control systemsPID tuning, state-space models, Bode plots
Image processingFiltering, segmentation, feature extraction
CommunicationsModulation, BER analysis, channel modeling
FinanceRisk analysis, portfolio optimization, Monte Carlo
AutomotiveADAS algorithms, powertrain modeling
AerospaceFlight dynamics, navigation, orbit mechanics
RoboticsKinematics, path planning, sensor fusion
BiomedicalECG/EEG analysis, medical imaging
AcademiaResearch, teaching, homework assignments

Frequently Asked Questions

  • Does the tool upload my data?

    No. All conversion happens locally in your browser using JavaScript. Your CSV data never leaves your device.

  • What MATLAB data type does the tool generate?

    For mixed-type data (strings and numbers), the tool generates a cell array using {} syntax. For pure numeric data, it generates a matrix using [] syntax.

  • What is the difference between [] and {} in MATLAB?

    [] creates a matrix (all elements must be numeric). {} creates a cell array (each cell can hold any type). Use matrices for math; use cell arrays for mixed data.

  • What is the difference between () and {} for indexing?

    A(i, j) accesses a matrix element by position. C{i, j} accesses a cell's content. C(i, j) returns a cell (not its content).

  • Can I use the output in MATLAB Live Scripts?

    Yes. Paste the generated code directly into a MATLAB Live Script (.mlx) code block.

  • What is the difference between this tool and readmatrix()?

    readmatrix() reads CSV files at runtime from disk. This tool generates MATLAB source code with hardcoded array literals. Use this for static data, testing, and demos; use readmatrix() for dynamic data.

  • What about readtable() and readcell()?

    readtable() imports CSV as a table with named columns. readcell() imports as a cell array. Both require the file at runtime. This tool generates standalone code that works without any file.

  • Can I edit the data before converting?

    Yes. The built-in table editor lets you modify cells, transpose, deduplicate, find/replace, change case, and insert/delete rows and columns.

  • What CSV formats are supported?

    Standard CSV (.csv) and TSV (.tsv) files with comma or tab delimiters.

  • Is there a file size limit?

    The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.

  • Can I use this on mobile?

    Yes. The tool is responsive, though the table editor is best experienced on desktop.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.

Excel To JSON

Free online Excel to JSON converter. Transform XLSX, XLS, XLSM files into JSON arrays, objects, or keyed formats instantly in your browser — no upload, 100% private.
Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.

Excel To CSV

Free Excel to CSV converter. Convert XLSX, XLS, XLSM to CSV instantly in your browser. No upload, 100% private. Edit, transpose, deduplicate before exporting.
Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.

Excel To SQL

Free online Excel to SQL converter. Generate CREATE TABLE and INSERT statements from spreadsheets for MySQL, PostgreSQL, SQLite, and SQL Server. Supports batch insert, primary keys, and type inference.
Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.

Excel To ASCII Table

Free online Excel to ASCII table converter with 10 border styles (MySQL, Unicode, reStructuredText, and more). Add code comment wrappers in 8 languages. Supports text alignment. Client-side processing.