Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Copy and paste data in the same CSV file using matlab

Date: 2023-08-11 14:33:58

Hello,
 
I have a CSV file with 720 rows and 2 columns. First column of the file has to be extrapolated to 1420 rows with some function and second column has to be extrapolated to 1420 rows by copying/repeating the same data as in first 720 rows (original data present in second column). I am Successful in extrapolating the first column but getting stuck in the second column. Can anybody help me? Example:
 
Original file
 
0.0   0.82
2.1   0.72
4.2   0.68 
6.3   0.15

Modified file

0.0   0.82
2.1   0.72
4.2   0.68 
6.3   0.15
8.4   0.82
10.5  0.72
12.6  0.68
14.7  0.15

Expert Answer:

:

Method One Hard-coded replication of rows (twice in this example):

 

>> X = [0.0,0.82; 2.1,0.72; 4.2,0.68; 6.3,0.15];
>> D = mean(diff(X(:,1)));
>> Y(:,2) = [X(:,2);X(:,2)];
>> Y(:,1) = [X(:,1);X(:,1)+X(end,1)+D]
Y =

           0    0.8200
      2.1000    0.7200
      4.2000    0.6800
      6.3000    0.1500
      8.4000    0.8200
     10.5000    0.7200
     12.6000    0.6800
     14.7000    0.1500

Method Two Number of rows replicated by a constant (thrice in this example):

>> N = 3;
>> Z(:,2) = repmat(X(:,2),N,1);
>> Z(:,1) = linspace(0,D*(N*size(X,1)-1),size(Z,1))
Z =
       0    0.8200
  2.1000    0.7200
  4.2000    0.6800
  6.3000    0.1500
  8.4000    0.8200
 10.5000    0.7200
 12.6000    0.6800
 14.7000    0.1500
 16.8000    0.8200
 18.9000    0.7200
 21.0000    0.6800
 23.1000    0.1500

 

Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

Our Comprehensive Matlab Assignment Help Services

Personalized Tutoring:Our team of MATLAB experts offers one-on-one tutoring sessions tailored to your specific needs. Whether you’re struggling with basic concepts or advanced algorithms, we provide clear, step-by-step guidance to help you understand and master MATLAB.

Assignment Assistance:Facing tight deadlines or complex assignments? We’re here to help! From initial problem analysis to code development and debugging, we offer full-spectrum support to ensure your assignments meet the highest standards.

Project Development: Need help with a research project? Our specialists can assist you in designing and implementing robust MATLAB solutions. We cover everything from project planning and data collection to coding, simulation, and result analysis.

Coursework Support: We provide comprehensive support for your coursework, helping you understand lectures, complete lab exercises, and prepare for exams. Our goal is to ensure you grasp the core principles and practical applications of MATLAB.

Thesis and Dissertation Guidance:Writing a thesis or dissertation? Our experts can assist you in incorporating MATLAB for data analysis, modeling, and simulation. We help you develop a strong methodological framework and ensure your research stands out.

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com