How to add a new column to the beginning of a csv file using matlab

I have a csv file with 30 rows and 20 columns and I want to write a new column of values at the beginning of the file so that the resuling file has 30 rows and 21 columns using matlab. Any help regarding this would be appreciated.

Answers (1)

% Step 1 - Read the file
M = csvread(filename)
% Step 2 - Add a column to the data
M = [NewColumn M]
% Step 3 - Save the file
csvwrite(filename, M)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Asked:

on 2 Mar 2016

Answered:

on 2 Mar 2016

Community Treasure Hunt

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

Start Hunting!