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
2 个评论
采纳的回答
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 个评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!