MATLAB: Matrix consisting of sub-elements of another matrix matrix Say I have the following matrix: x = [ 1 2 3 4 5 6 7 8 9] If I want a matrix that consists of the following: y = [1 2 4 5 9] How would I go about doing this? Best Answer By indexing,e.g.,>> x = [ 1 2 3 4 5 6 7 8 9]*10;>> y=x([1,2,4,5,9])y = 10 20 40 50 90 Related SolutionsMATLAB: Making GUI with sub-elements resizable in a quick way Add this line at the end of the code, which defines the GUI set( findall( fig_handle, '-property', 'Units' ), 'Units', 'Normalized' ) MATLAB: Help with removing duplicate sub-elements…. Use isnan and diff to create some indices, then replace those values:>> A = [-2 -2 -2 -2 NaN NaN NaN -3 -3 -3 -3 NaN NaN -2 -2 -2 NaN -3 -3 NaN NaN 1 1 1 1 NaN NaN 4 4 4 NaN NaN 3 3 3 NaN]A = -2 -2 -2 -2 NaN NaN NaN -3 -3 -3 -3 NaN NaN -2 -2 -2 NaN -3 -3 NaN NaN 1 1 1 1 NaN NaN 4 4 4 NaN NaN 3 3 3 NaN>> B = A;>> B(-1<diff(isnan([NaN,A]))) = NaNB = -2 NaN NaN NaN NaN NaN NaN -3 NaN NaN NaN NaN NaN -2 NaN NaN NaN -3 NaN NaN NaN 1 NaN NaN NaN NaN NaN 4 NaN NaN NaN NaN 3 NaN NaN NaN Related QuestionHow to make a reference to multiple subelements of a cell without for loop (to create a plot)How to plot this functionHow to create a 3D matrix using the 2D matricesHow to delete elements on specific indices
Best Answer