How do I create a matrix A which is equal to a matrix X with column vectors added onto it which are the element wise square and cube of some of the columns of X? I have a matrix that is 32413×46 and I want to take columns 12-18, square them and add them as columns 47-53 to the previous matrix and then take those same columns 12-18, cube them and add them on as columns 54-60.
MATLAB: Matrix “addition” qeustion
matrix math
Related Solutions
cur_varnames = YourTable.Properties.VariableNames;for K = [10, 12:18] thisvarname = cur_varnames{K}; thisval = YourTable.(thisvarname); sq_varname = [thisvarname '_squared']; cu_varname = [thisvarname '_cubed']; YourTable.(sq_varname) = thisval .^ 2; YourTable.(cu_varname) = thisval .^ 3;end
>> X = [1;2;3;4;5;6];>> Y = bsxfun(@plus,X,0:10:40);>> Z = bsxfun(@plus,Y(:),0:20);>> ZZ = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
Best Answer