From: MOOON MOOON on 12 May 2010 12:14 Hello, I want to know the method of creating a matrix from an existing matrix depending on certain specifications made by the user. for example, assume we have the matrix: x=[2 3 5 9 2 3 6 8 1 0 6 9] I want to create a new matrix that takes only the two elements then ignore the third one and then take the next two elements and ignore the third and so on. So, depending on the above matrix, the new matrix is: y=[2 3 9 2 6 8 0 6] Also, another example is making a new matrix that takes the entries that have odd sequence i.e entries number 1,3,5,7,9,11 which are in the above example: [ 2 5 2 6 1 6] or , in general, any specifications or rules made by the user. Could you please help me to solve this problem. Thanks..
From: James Tursa on 12 May 2010 12:27 "MOOON MOOON" <shaheed107(a)yahoo.com> wrote in message <hsek4c$qng$1(a)fred.mathworks.com>... > > Hello, > > I want to know the method of creating a matrix > > from an existing matrix depending on certain > > specifications made by the user. > > for example, > > assume we have the matrix: > > x=[2 3 5 9 2 3 6 8 1 0 6 9] > > I want to create a new matrix that takes > > only the two elements then ignore the third > > one and then take the next two elements and > > ignore the third and so on. > > So, depending on the above matrix, > > the new matrix is: > > y=[2 3 9 2 6 8 0 6] > > Also, another example is making a new matrix > > that takes the entries that have odd sequence > > i.e entries number 1,3,5,7,9,11 > > which are in the above example: [ 2 5 2 6 1 6] > > or , in general, any specifications or rules made by > > the user. > > Could you please help me to solve > > this problem. > > Thanks.. To lop off every 3rd value, assuming that the total number of elements is a multiple of three: A = rand(3*n); A = reshape(A,3,[]); A = A(1:2,:); A = reshape(A,1,[]); To lop off every other value, assuming that the total number of elements is a multiple of two: A = rand(2*n); A = reshape(A,2,[]); A = A(1,:); Basically, consider how the values are laid out in memory, then a reshape and array slice operation will often suffice. James Tursa
From: Matt J on 12 May 2010 12:29 "MOOON MOOON" <shaheed107(a)yahoo.com> wrote in message <hsek4c$qng$1(a)fred.mathworks.com>... > assume we have the matrix: > > x=[2 3 5 9 2 3 6 8 1 0 6 9] > > I want to create a new matrix that takes > > only the two elements then ignore the third > > one and then take the next two elements and > > ignore the third and so on. > > So, depending on the above matrix, > > the new matrix is: > > y=[2 3 9 2 6 8 0 6] > ================= y=x; y(3:3:end)=[], %or in your second example y(2:2:end)=[]
From: Matt Fig on 12 May 2010 12:40 x=[2 3 5 9 2 3 6 8 1 0 6 9]; x(3:3:end) = [] % Pruning technique x=[2 3 5 9 2 3 6 8 1 0 6 9]; x = x(1:2:end) % Selecting technique
From: MOOON MOOON on 12 May 2010 17:58 Ok very great that works very good I want to thank everyone who gave me this help thanks thanks thanks
|
Next
|
Last
Pages: 1 2 Prev: Getting a GUI to work with simulink Next: fminsearch and multiple inputs to function |