Creating a new table column that is the range of numbersbetween two other column
14 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm trying to add a new column to a table, that each row is the range between two numbers corresponding to two other existing columns.
Somthing like this:
K>> RESULTS_T
RESULTS_T =
2091×4 table
y_tl x_tl y_br x_br
____ ____ ____ ____
54 119 60 129
177 119 183 129
300 119 306 129
423 119 429 129
546 119 552 129
669 119 675 129
792 119 798 129
#########################################
y_range
y_tl : y_br
#########################################
I manage to do so only for a single row:
K>> {RESULTS_T{:,1} : RESULTS_T{:,3}}
ans =
1×1 cell array
{[54 55 56 57 58 59 60]}
0 个评论
回答(1 个)
Rik
2021-10-28
You can either use a loop, or hide the loop with rowfun:
data=[54 119 60 129
177 119 183 129
300 119 306 129
423 119 429 129
546 119 552 129
669 119 675 129
792 119 798 129];
ytl=data(:,1);
ybr=data(:,3);
RESULTS_T =table(ytl,ybr);
[RESULTS_T rowfun(@(ytl,ybr)ytl:ybr,RESULTS_T,'OutputVariableNames','range') ]
7 个评论
Rik
2021-11-2
What have you tried yourself already? If you try something and post the result it will probably be easy to adapt.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!