How can I copy a column I already have and add it on to the end of my matrix?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
William Campbell
il 17 Gen 2019
Modificato: madhan ravi
il 17 Gen 2019
I have some data with time followed by various parameters (see example below)
All I want to do is take the 3rd column (4th if you include the time) and create a new column at the end with the same data
2018-01-01T01:00 53.000 0.000 268.450 -1.000 0.100 157.000
2018-01-01T02:00 53.000 0.000 267.750 -1.000 0.200 51.000
2018-01-01T03:00 53.000 0.000 268.450 -1.000 0.100 142.000
2018-01-01T04:00 53.000 0.000 269.550 -1.000 0.200 14.000
I would really appreciate some help with this!
Thanks
2 Commenti
Risposta accettata
madhan ravi
il 17 Gen 2019
Modificato: madhan ravi
il 17 Gen 2019
EDITED
https://www.mathworks.com/help/matlab/ref/addvars.html - as you already have it as a table like shown in your previous question.
Example:
T=readtable('sample.txt'); % your rawdata filename
T.Var1=datetime(T.Var1,'Format','yyyy-MM-dd''T''mm:ss')
New=addvars(T,T{:,4},'After',size(T,2))
Gives:
New =
4×8 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8
________________ ____ ____ ______ ____ ____ ____ ______
2018-01-01T01:00 53 0 268.45 -1 0.1 157 268.45
2018-01-01T02:00 53 0 267.75 -1 0.2 51 267.75
2018-01-01T03:00 53 0 268.45 -1 0.1 142 268.45
2018-01-01T04:00 53 0 269.55 -1 0.2 14 269.55
Download the attached file to experiment.
10 Commenti
madhan ravi
il 17 Gen 2019
Modificato: madhan ravi
il 17 Gen 2019
OK final answer , if you have anymore questions please post a separate question:
NN=table2cell(T);
S=size(T);
New=cell(S(1),S(end)+1);
N=5; % the number of column which you want to add new values to
New(:,[1:N-1 N+1:end])=NN;
New(:,N)=NN(:,4); % copies the 4th column to where ever you it to be copied to (Nth column)
T=cell2table(New)
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Logical 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!