How can I add data to an existing double at specific points?

19 views (last 30 days)
Ruth Ronalter on 12 Aug 2021
Commented: Ruth Ronalter on 19 Aug 2021
Hello,
I have this 14x1 double, I need to add 3 more data points at specific locations, effectively making it a 17x1 double. It looks like this named mean_RT
765
413
309.006493506494
288.863636363636
562.833333333333
408
925.333333333333
605
201.800000000000
530
431.666666666667
640.659574468085
625.500000000000
851.666666666667
advars is only applicable on tables, I tried expanding it with undefined values as
mean_RT = nan(17,1)
but that just creates a double of 17 Nans. I tried indexing a 0 at the points I needed (these are test subject averages that need to be the same location for statistical purposes)
mean_RT([2,13,14]) = 0
and while it does insert a zero at the technical point, instead of adding a value, it replaces the value so my double is still 14x1. It I try for separate points such as
mean_RT([2,1],[13,1],[14,1])= 0
I wind up with a 14x13x14 double. What am I doing wrong?

Dave B on 12 Aug 2021
The easy to think about solution might feel a little messy:
% insert the numbers 13 and 18 between a(2)/a(3) and a(4)/a(5)
a=1:5
a = 1×5
1 2 3 4 5
b=[a(1:2) 13 a(3:4) 18 a(5)]
b = 1×7
1 2 13 3 4 18 5
How about taking this strategy, make the new array all NaN, assign the new values, then assign the old array to the remaining NaNs?
a = 1:5;
b = nan(1,7);
b([3 6]) = [13 18];
b(isnan(b)) = a
b = 1×7
1 2 13 3 4 18 5
Ruth Ronalter on 19 Aug 2021
Sorry, realized I never accepted your answer. I got both methods to work, thank you for taking the time to explain it to me and making it work.

Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by