How can I copy a column I already have and add it on to the end of my matrix?

5 次查看(过去 30 天)
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

采纳的回答

madhan ravi
madhan ravi 2019-1-17
编辑:madhan ravi 2019-1-17
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 个评论
William Campbell
William Campbell 2019-1-17
Thanks that has worked for the zeros
All i want to do now is replicate the 4th column and it can go anywhere in the data but it just has to be replicated somewhere
Thanks again!
2018010100.00000 153 0 -4.70000000000000 72.5000000000000 0.500000000000000 231 0
2018010101.00000 153 0 -6.40000000000000 91.5000000000000 0.300000000000000 5 0
2018010102.00000 153 0 -6.20000000000000 94 0.700000000000000 61 0
2018010103.00000 153 0 -5.40000000000000 94 1 72 0
2018010104.00000 153 0 -5.50000000000000 98 0.600000000000000 253 0
2018010105.00000 153 0 -6.30000000000000 100 2.60000000000000 328 0
2018010106.00000 153 0 -8.10000000000000 100 7.40000000000000 327 0
2018010107.00000 157 0 -8.80000000000000 100 5.60000000000000 328 0
madhan ravi
madhan ravi 2019-1-17
编辑:madhan ravi 2019-1-17
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)

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2019-1-17
A = [A A(:,4)];

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by