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

16 Ansichten (letzte 30 Tage)
Manoj Murali
Manoj Murali am 10 Feb. 2012
Beantwortet: nick am 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..!!

Antworten (1)

nick
nick am 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

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by