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

6 vues (au cours des 30 derniers jours)
Manoj Murali
Manoj Murali le 10 Fév 2012
Réponse apportée : nick le 17 Avr 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..!!

Réponses (1)

nick
nick le 17 Avr 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

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by