Creating a new table column that is the range of numbersbetween two other column
20 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Rik
on 28 Oct 2021
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 Comments
Rik
on 2 Nov 2021
What have you tried yourself already? If you try something and post the result it will probably be easy to adapt.
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!