From: Gavin Dooley on 23 Jan 2010 07:52 I'm quite new to matlab I can program using c++ but im sure there are easier ways of doing what im doing... Also I am having some simple problems which need sorting... 1) How can you take the 1 column of data out of a matrix and assign it to a differnt 1columned matrix? i.e if p = [ 1 1 1 ; 2 3 4 ; 4 5 6] how can i take this data and get a column vector of the first column ?e.g. 1 2 4 without using a for loop? 2) How can you sort the above matrix only by the first column ascending or the second column?... When i do it it sorts all the values into ascending order. 3) THe surface im trying to creat using surf is not turning out well, Does it need to be sort into ascending order of x,y or z values? My points make up a plane when using plots 3 and plotting them using 'o' however the surf isnt turning out well...
From: Rune Allnor on 23 Jan 2010 07:59 On 23 Jan, 13:52, "Gavin Dooley" <doole...(a)tcd.ie> wrote: > I'm quite new to matlab I can program using c++ but im sure there are easier ways of doing what im doing... Why would anyone who already know C++ want to step down to matlab...? > Also I am having some simple problems which need sorting... > > 1) How can you take the 1 column of data out of a matrix and assign it to a differnt 1columned matrix? > i.e if > p = [ 1 1 1 ; 2 3 4 ; 4 5 6] > how can i take this data and get a column vector of the first column ?e.g.. 1 2 4 > without using a for loop? pp = p(:,1) > 2) How can you sort the above matrix only by the first column ascending or the second column?... When i do it it sorts all the values into ascending order. doc sort Pay attention to the variant where *two* results are returned. > 3) THe surface im trying to creat using surf is not turning out well, Does it need to be sort into ascending order of x,y or z values? My points make up a plane when using plots 3 and plotting them using 'o' however the surf isnt turning out well... Post the code you use along with a SMALL!! example of representative data points (preferably less than 10 data points) and somebody might be able to answer. Rune
From: Wayne King on 23 Jan 2010 08:11 "Gavin Dooley" <dooleygj(a)tcd.ie> wrote in message <hjerdi$jm0$1(a)fred.mathworks.com>... > I'm quite new to matlab I can program using c++ but im sure there are easier ways of doing what im doing... Also I am having some simple problems which need sorting... > > > 1) How can you take the 1 column of data out of a matrix and assign it to a differnt 1columned matrix? > i.e if > p = [ 1 1 1 ; 2 3 4 ; 4 5 6] > how can i take this data and get a column vector of the first column ?e.g. 1 2 4 > without using a for loop? > > 2) How can you sort the above matrix only by the first column ascending or the second column?... When i do it it sorts all the values into ascending order. > > 3) THe surface im trying to creat using surf is not turning out well, Does it need to be sort into ascending order of x,y or z values? My points make up a plane when using plots 3 and plotting them using 'o' however the surf isnt turning out well... Hi Gavin, The things you are trying to do are very easy in Matlab: 1.) X = p(:,1); % gives the 1st column of p 2.) If you look at the help for sort(), you will see that you can specify 'ascend' or 'descend' as the mode and furthermore you can specify the dimension of the input you want to sort over. 3.) Look at meshgrid() to get an idea of how to create a grid suitable for input to surf(). I think you'll find Matlab a very powerful tool, but you should spend some time reading the documentation. The doc is pretty good and I think you'll find a lot of the above questions answered. Welcome to Matlab. Wayne
From: Leclerc on 23 Jan 2010 08:30 >> I'm quite new to matlab I can program using c++ but im sure there are easier ways of doing what im doing... > > Why would anyone who already know C++ want to step down > to matlab...? ??? I professionaly program in C++ (technical and numerical applications) for several yuear now, and "step down" to matlab every time when I need to develop some new algorithm (i.e. solve problem). Working out algorithms in matlab + rewriting it in c++ proved to be much (*much*) faster, comared to direct development using c++ only.
From: Gavin Dooley on 23 Jan 2010 10:51 Thanks for the ans to my first question that will quicken up my programming no end! 2) Im looking to sort say the 2 column in a 100x3 matrix in ascending order, the dimension one is not working for me. if q = 1 2 3 4 0 1 7 9 6 3 5 7 using px = sort(q,2) I get: px = 1 2 3 0 1 4 6 7 9 3 5 7 I want 4 0 1 1 2 3 3 5 7 7 9 6 Thanks,
|
Next
|
Last
Pages: 1 2 Prev: modnorm function in Next: Errors during mex compilation on certain systems |