How to append data or values to an existing .csv file??

1 visualizzazione (ultimi 30 giorni)
Manoj Murali
Manoj Murali il 10 Feb 2012
Risposto: nick il 17 Apr 2025
hi..suppose i have a .csv file named csvfile.csv.And it has the values as follows:
23 45
69 84
48 78
12 34
so it has two colums.Now wat i need to do is to add values staring from the 3rd colum with out deleting the values in the 1st and 2nd colums..How can i do this...??Any one plz help..!!

Risposte (1)

nick
nick il 17 Apr 2025
Hello Manoj,
To add a third column to an existing CSV file in MATLAB without deleting the values in the first and second columns, you can follow these steps:
% Step 1: Read the existing CSV file
existingData = csvread('file.csv');
% Step 2: Create the new column data (example data)
newColumn = [100; 200; 300; 400]; % Make sure it has the same number of rows
% Step 3: Combine the existing data with the new column
updatedData = [existingData, newColumn];
% Step 4: Write the updated data back to the CSV file
csvwrite(updatedData, 'file.csv');
Kindly refer to the documentation by executing the following command in MATLAB Command Window to know more about 'csvread' and 'csvwrite' :
doc csvread
doc csvwrite

Categorie

Scopri di più su MATLAB Report Generator in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by