# Matlab - Array Manipulation and Tricks | blinkdagger

an Engineering and MATLAB blog Home Listchecker MATLAB Contact About

Matlab - Tips and Tricks on Manipulating 1-D Arrays (Vectors)
14 Jan 2008 Quan Quach 175 comments 24,044 views

Introduction
1-D Arrays (also known as vectors) are commonly used within Matlab, so it is a good idea to understand how they work and how to bend them to your will. This is a quick tutorial on some simple tricks that you may or may not know about vectors.

Creating Vectors
1. How to create a row vector that increments by 1. For example, let’s create a row vector that goes from 1 to 10, with increments of 1.
myVector = [1 2 3 4 5 6 7 8 9 10]; %the hard way myVector = 1:10 %the easy way

2. How to transform a row vector to a column vector, and vice versa.
myVector = 1:10; %creates a row vector myVector = myVector' %this is the complex conjugate transpose myVector = myVector.' %is the non-conjugate transpose

Note: Dan Kominsky pointed out that is a subtle but important difference here. When you are working with real numbers the difference is irrelevant, but when you are dealing with complex numbers, the meaning is entirely different! Thanks for the correction, Dan. 3. How to create a column vector that increments by 1. For example, let’s create a column vector that goes from 1 to 10, with increments of 1.
myVector = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]; %the hard way myVector = [1:10].' %the easy way

4. How to create a vector that increments by a specific value. Let’s create a vector that goes from 1 to 19, and increments by 2. Note that the increment value is not limited to integers.
myVector = 1:2:19

5. How to create a vector that decrements by a specific value. Let’s create a vector that goes from 10 to 1, and decrements by 1
myVector = 10:-1:1

6. How to create a vector with equally spaced points. Let’s create a vector that goes from 0 to 100 with 21 equally spaced points.
%first argument is the start value of the vector

1 of 45

3/25/2011 1:43 AM

Matlab - Array Manipulation and Tricks | blinkdagger

%second argument is the end value of the vector %third argument is the number of points within the vector myVector = linspace(0,100,21)

7. How to create a vector of zeros. For example, let’s create a vector of 10 zeros.
%first argument is the number of rows %second argument is the number of columns rowZeros = zeros(1,10)

Note: Incidentally, this is a great way to preallocate a vector. Preallocating a vector is most useful when FOR loops are involved. Preallocating a vector is preferred over resizing a vector repeatedly as it reduces the processing time. 8. How to create a vector of ones. For example, let’s create a vector of 10 ones.
%first argument is the number of rows %second argument is the number of columns rowOnes = ones(1,10)

Note: This is yet another way to preallocate a vector.

Adding, Removing, and Replacing Elements within a Vector
9. How to append a vector. For example, lets add 11 to the end of the vector
myVector = 1:10; myVector = [myVector 11] %we can also add 11 to the beginning of the vector myVector = [11 myVector];

Note: This method of appending vectors should not be used within large FOR loops. When resizing arrays, memory must be reallocated with a larger size. If this is done repeatedly, there is a speed penalty. 10. How to append two vectors together.
myVector1 = 1:5; myVector2 = 6:10; myVectorAppend = [myVector1 myVector2] %myVectorAppend = cat(2,myVector1,myVector2) does the same thing

Note: Same warning as above. 11. How to remove a particular element from a vector. Lets say we want to remove the 4th entry.
myVector = 1:10; myVector(4) = []

12. How to replace a particular element with a different element within a vector. Lets say we want to replace the 4th entry with the value of 100.
myVector = 1:10; myVector(4) = 100

13. How to remove the last element from a vector.
myVector = 1:10; myVector(end) = []

14. How to remove the last 5 elements.
myVector = 1:10; myVector(end-4:end) = []

15. How to keep the last 5 elements (or equivalently, remove the first five elements).

2 of 45

3/25/2011 1:43 AM

Matlab - Array Manipulation and Tricks | blinkdagger

myVector = 1:10; myVector = myVector(end-4:end) %the following command does the same thing myVector(1:5) =[];

16. How to remove a series of elements. For example, let’s remove entries 3 through 6:
myVector = 1:10; myVector(3:6) = []

17. How to keep a series of elements. For example, let’s keep entries 3 through 6:
myVector = 1:10; myVector = myVector(3:6)

18. How to remove a group of specific elements. For example, lets remove entries 2,5, and 7:
myVector = 1:10; myVector([2,5,7]) = []

19. How to keep a group of specific elements. For example, lets keep entries 2,5, and 7:
myVector = 1:10; myVector = myVector([2,5,7])

20. How to get the number of elements within a vector. Useful when creating a for loop to run through a vector.
myVector = 1:10; numElements = length(myVector) %the following command does the same thing numElements = numel(myVector)

21. How to remove all zeros from a vector.
myVector = [0 0 0 1 2 3 0 0 4 5 1 2 0 0]; %index contains the indices elements within myVector which are non-zero index = find(myVector); myVector = myVector(index) %removes all the zeros within the vector

Alternatively, logical indexing can be used (and is more efficient)
myVector(myVector == 0) = [];

22. How to remove a particular value from a vector. For example, how to remove any occurence of 6 within a vector
myVector = [6 6 0 1 2 3 0 0 6 6 1 2 0 0]; %index contains the indices of elements within myVector which are equal to 6 index = find(myVector == 6 ); myVector(index) = []

Alternatively, logical indexing can be used (and is more efficient)
myVector(myVector == 6) = [];

23. How to remove the first two occurences of 6 within a vector
myVector = [6 6 0 1 2 3 0 0 6 6 1 2 0 0]; index = find(myVector == 6,2); myVector(index) = []

24. How to remove all elements greater than 5 from a vector.
myVector = [10 0 0 1 12 3 0 0 4 5 1 12 0 0]; %index contains indices of elements within myVector which are greater than 5

3 of 45

3/25/2011 1:43 AM

Matlab - Array Manipulation and Tricks | blinkdagger

index = find(myVector > 5); myVector(index) = []

Alternatively, logical indexing can be used (and is more efficient)
myVector(myVector > 5) = [];

25. Similarly, how to remove all elements less than 5 from a vector.
myVector = [10 0 0 1 12 3 0 0 4 5 1 12 0 0]; %index contains the indices of elements within myVector which are less than 5 index = find(myVector < 5); myVector(index) = []

Alternatively, logical indexing can be used (and is more efficient)
myVector(myVector < 5) = [];

Sorting and Shifting Vectors
26. How to reverse a vector.
myVector = 1:10; myVector = myVector(end:-1:1)

27. How to sort a vector.
myVector = [10 0 0 1 12 3 0 0 4 5 1 12 0 0]; myVectorAscend = sort(myVector) %sort ascending myVectorDescend = sort(myVector,'descend') %sort descending

28. How to shift the elements one spot to the right.
myVector = 1:10; myVector = myVector([end 1:end-1])

29. How to shift the elements one spot to the left.
myVector = 1:10; myVector2 = myVector([2:end 1])

Other useful commands:
30. How to get the maximum and minimum value of a vector
myVector = [10 0 0 1 12 3 0 0 4 5 1 12 0 0]; maxValue = max(myVector); minValue = min(myVector);

31. How to add up all the elements within a vector.
myVector = 1:10; total = sum(myVector);

32. How to get the product of all the elements within a vector.
myVector = 1:10; total = prod(myVector);

33. How to get the average, standard deviation, and variance of a vector.
myVector = 1:10; averageArray = mean(myVector) stdArray = std(myVector) varArray = var(myVector)

4 of 45

3/25/2011 1:43 AM

on 21 Jan 2008 at 3:23 pm 6Quan Quach Try using the repmat command. on 14 Jan 2008 at 2:14 pm 2Quan Quach Dan K: Thanks for the correction. The transpose of a vector is NOT myVector’ ! It is myVector.4). Dan 4.’ When you are working with real numbers the difference is irrelevant. Hope this helps.. It is a subtle. HTH..Array Manipulation and Tricks | blinkdagger http://blinkdagger. but important point!! I have edited the post to reflect your comment. Quan 3. myVector(index) = [] Whereas a faster implementaiton (and. % the matrix you are multiplying into. Thanks.Matlab . on 15 Jan 2008 at 7:56 pm 4Quan Quach Thanks Again Dan. please share at least one! 175 Responses to “Matlab . there is one other major area in which your code is inefficient (although functionally correct). Is there any way to do it? 6. myVectorRepeated = repmat(myVector. Your suggestion is duly noted and I have edited the post to reflect it. Quan.4] %the vector you will be multiplying with myMatrix = magic(4). 5. It is generally significantly faster to use logical indexing rather than the find command. I think more clear) is: myVector(myVector >5)=[]. For example: myVector = [1.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. on 21 Jan 2008 at 2:40 pm 5Vahid I need to muliple a vector to every single column (as the same size of the vector) of a matrix element by element without using the for loop. but the myVector’ is the complex conjugate of the transpose! And believe me it is a royal pain to debug that mistake. on 15 Jan 2008 at 7:31 am 3Dan K Actually. 5 of 45 3/25/2011 1:43 AM . on 14 Jan 2008 at 7:46 am 1Dan K I’m sorry to tell you that you made one of the classic blunders of matlab programming.Tips and Tricks on Manipulating 1-D Arrays (Vectors)” 1.1. For example in item number 24 you use: index = find(myVector > 5). Got any tricks up your sleeve? There are a ton of Matlab tricks that were not covered in this tutorial.2. Do you know of any super useful trick? If you have any of your own tips and tricks up your sleeve.3. Dan 2. since it is a coding error that is very hard to see.

but doesn’t know the index of b in a.8]. 13. how to make a program? 12. a(indicesToRemove.:}={}.:) = [].g.indicesToRemove) = []. 10.eg. on 09 Mar 2008 at 2:43 pm 8Percy I’ve got a question about removind some indices from a cell. on 26 Mar 2008 at 12:21 am 12jack assuming that I just have the vectors of a and b. on 26 Mar 2008 at 12:45 am 13Daniel Sutoyo hey jack you can use the command setdiff(a. myAnswer = myMatrix . Great work! 8.10).ind}={}. Try this: a(:. such that the dimension of a is [7. Dan comments were even better.* myVectorRepeated.b.5. vector1 a=[1 2. e..7] it doesn’t work to put these to a{ind. a=cell(10.Array Manipulation and Tricks | blinkdagger http://blinkdagger. a{:. on 26 Mar 2008 at 12:19 am 11jack if I have two vectors that have different length. 2 1] and I want of delete the elements from vector1 a that have the same values with vector2 b? without using loop. I want to remove both the 3th.5th and 8th columns AND rows.. on 16 Feb 2008 at 9:52 am 7Dave I visited your website and i found it very useful. or does it? 9.’rows’) 6 of 45 3/25/2011 1:43 AM .Matlab . %notice the dot before the multipy 7. on 12 Mar 2008 at 3:06 am 10anuj My question is How can I remove rows in a matrix that have third element in the column 0 Input123 230 023 020 Answer should be123 023 11. on 09 Mar 2008 at 3:05 pm 9Quan Quach Percy. 2 1] and vector2 b=[ 1 2.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. 0 1. indicesToRemove = [3.

20. The following code is taking much time any idea how to make it run faster? omegac. [y.bb are vecotrs of of length n. What I need is a vector containing indices of the sorted values in original vector y. p=[].00 0.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. 7 of 45 3/25/2011 1:43 AM .Y.00 0.betac are scalars. on 28 Mar 2008 at 2:19 pm 17Daniel Sutoyo Takkari.30 9. 14.alphac. for i=1:length(x) p=[p find(y==x(i))]. on 28 Mar 2008 at 2:19 pm 18takkari This code do the same job but takes much time: x=sort(y). on 27 Mar 2008 at 11:25 pm 15Quan Quach Takkari.09 How can I implement this code in matlab as there is no order() function? 15.Matlab .20 1. 17.i] = sort(y) y is your new sorted values i will be you indices 18.. I am coverting R code into Matlab and have no idea how to do the following: >y z order(y) [1] 1 3 8 2 5 4 6 7 >pp [1] 0.80 3. on 28 Mar 2008 at 11:32 am 16takkari Hi Quan. on 31 Mar 2008 at 1:51 pm 20takkari Hi Dear. end length of x is 392480 19. on 27 Mar 2008 at 9:49 pm 14takkari Hi. Quan 16. Instead of showing us the R code.30 0. h.b. b(t)=Y(t-1).Array Manipulation and Tricks | blinkdagger http://blinkdagger. sort(y) just sort the data. for t=3:n h(t)=omegac+alphac*Y(t-1)+betac*h(t-1). Problem solved. on 28 Mar 2008 at 3:04 pm 19takkari Thanks Daniel.10 0.. You could have said that in the first place. Maybe the sort function is what you are looking for.

2)==0)=0 returns 0 for all the even values of n n(rem(n. bb(t)=bb(t)+alphac*(j-1)*((betac)^(j-2))*Y(t-j). You have a great website! Thanks 23.Array Manipulation and Tricks | blinkdagger http://blinkdagger. for j=2:(t-1) b(t)=b(t)+((betac)^(j-1))*Y(t-j). end end 22. for t=3:n for j=2:(t-1) b(t)=b(t)+((betac)^(j-1))*Y(t-j).How can i get mean? 24. To prune it down. I found them extremely helpful.. on 06 Jun 2008 at 11:49 am 24sathya How about these? n(isprime(n))=0 returns 0 for all the primevalues of n n(rem(n. bb(t)=(omegac/(1-betac)^2). Everyone else’s comments were helpful as well. Quan h(3:n) = omegac + alphac*Y(2:n-1) + betac*h(2:n-1). on 28 May 2008 at 12:50 pm 22Jon V Hey! I just wanted to say that your MATLAB tutorials are great. >> unique(v) ans = 012 26. >> v=[0 0 1 1 2 2]. I got this error. Here’s something to get you started.2)~=0)=0 returns 0 for all the odd values of n 25. on 31 Mar 2008 at 3:33 pm 21Quan Quach Takkari. bb(3:n)=(omegac/(1-betac)^2). bb(t)=bb(t)+alphac*(j-1)*((betac)^(j-2))*Y(t-j). on 25 Jun 2008 at 8:03 am 26Ashley 8 of 45 3/25/2011 1:43 AM .. on 06 Jun 2008 at 11:34 am 23sathya n=1:10.m Line: 2 Column: 1 Function definitions are not permitted at the prompt or in scripts. on 08 Jun 2008 at 3:36 pm 25Travis Johnson I recently found the unique(V) function very useful in a permutations algorithm which generated the correct answer several ways and stored them all.Matlab . I used unique. end end Thanks 21. average=mean(n) ??? Error: File: mean.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. b(3:n) = Y(2:n).

on 24 Jul 2008 at 9:17 am 31tanuj but the problem is that my ‘A’ is of type uint16/uint32. 1) in a single command. t=cumsum(cumsum(a). 29. rowIndex . I need to access a 2-D array as a LUT.Matlab . Thanks for the useful article.. what do i do. 28.4) & (2.Array Manipulation and Tricks | blinkdagger http://blinkdagger. t(end) can this be reduced…. % size of rowIndex equal size columnIndex Can I get a vector of (3. (A can be any arbitary matrix) i want to sum all the elements above the value 2. How can i do that ? i mean i want 3+4+5+6=18(answer) Thanks a lot 30. 9 of 45 3/25/2011 1:43 AM . on 24 Jul 2008 at 5:48 am 29tanuj Hey thanks for nice tips.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. result = [34 21]. 4 5 6]. on 12 Aug 2008 at 4:30 am 32madhu Hello Dr Quan Quach . on 24 Jul 2008 at 6:10 am 30tanuj hey i guess i got the answer A = [1 2 3. then a(a<3)=0. example LUT = [11 12 13 14. Does anyone know how to do that? Thanks! 27. columnIndex )).. rowIndex = [3 2].4 5 6]. plz susggest thanks in advance 32. 21 22 23 24. on 14 Jul 2008 at 5:19 pm 27Mina Hey All. % if i want to add all the values greater than 3. on 14 Jul 2008 at 5:29 pm 28Mina I got it We can use result = LUT(sub2ind(size(LUT). columnIndex = [4 1]. I have a matrix and I want to remove all columns that are zeros.2). 31. and ‘cumsum’ is not valid for these types. 31 32 33 34]. I have a 2-D matrix A = [1 2 3.

Thanks in advance for any help! 35.Array Manipulation and Tricks | blinkdagger http://blinkdagger.6791 -0..14533 0. 9. on 23 Aug 2008 at 1:12 pm 34baba Good stuff here. Have you tried using the cftool command? That might do the trick Quan 34. I need a help on polynomial fit if i have to know the 2nd order polynomial fit coefficients(c) and respective errors(e) for x= [-1. 6.9597 -1. on 23 Aug 2008 at 8:51 pm 35Quan Quach Hi Baba. %second. And I’d like to have a code that gives the following result: Result = [1.3207 -0. remove all NaNs 10 of 45 3/25/2011 1:43 AM . 11.e I have to repeat this over many row vectors).3736 e = R: [3x3 double] df: 3 normr: 0.13484 0. pad all vectors using NaN so that they are the same length C = [9 10 11 NaN]. put all vectors into matrix form temp = [A. C = [9 10 11]. %third use the reshape function Result = reshape(temp.2) i got c = 0. 10.y.1).3930 -0. on 12 Aug 2008 at 9:33 am 33Quan Quach Madhu.1393 0. 3.0198] y= [-0.C].2373 -1.3737] I used command [c e]=polyfit(x.031 could you help me how to get the coefficients errors? Thank you madhu 33.Matlab .9390 -0. I was hoping if someone could help me with this problem that I need to get around in an efficient way (i.0788 -0. I’ve got 3 vectors : A = [1 2 3 4]. Here is my idea: %first. 4.3237 -1. 7. Say. B = [5 6 7 8].6931 -0. 8]. (note the unequal dims).. 5.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.8210 -0. 2.numel(temp).B.0669 actually here c is ok (as per our calculation a2 a1 a0) but e should come as 0. %fourth.2993 -1.

I want to know of a way to find a particular element and its corresponding index from a vector if it is greater than something.. I find your tips very useful and to the point.92. Could you help out please? Thanks. If I say find (vector>90) it gives all numbers >90. ? E. on 20 Oct 2008 at 5:19 pm 36asur010 Hi Quan. how can I just get the first number which is greater than the specified value. Quan 36. on 22 Dec 2008 at 3:03 pm 41Sathya Hi asur.60. break end end 38. Hi.93].90. For example I have a vector = [40. vec = [1 1 1 2 2 3 3 4 ] where k == 1 ans = 3 39.g.60. vec = [1 1 1 2 2 3 3 4 ] where k == 1 ans = 3 40.80.70. The find function usually returns all values which are greater than it.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. Thanks for that. on 16 Nov 2008 at 1:27 pm 40wladmir Thank you very much for your help and for your time!!! thank you very much!!! 41.91. I wonder if there is a built in function that would give me the number of times ‘k’ appears in a vector ? E. on 13 Nov 2008 at 6:32 am 38Graham Hi. on 05 Nov 2008 at 4:50 pm 37Anonymous Hi asur.50..Array Manipulation and Tricks | blinkdagger http://blinkdagger. 11 of 45 3/25/2011 1:43 AM . I wonder if there is a built in function that would give me the number of times ‘k’ appears in a vector without using the hist function.g. Adi 37. on 14 Nov 2008 at 5:44 am 39Graham sorry 4got to add. u can use for i=1:numel(vector) if vector(i) > 90 index=i. Result(isnan(Result)) = []..Matlab . I want to find the first element which is >90 and its corresponding index in the original vector.

If you need to sum up all the elements of A that are greater than 3. on 23 Dec 2008 at 9:39 pm 44Rob S.. % if you want to count how many 1's sum(vec==1) Hope this helps! Can’t find it right now. HTH. try this: A = [1 2 3. @ Tanuj. I see you had an interesting problem farther up the page. on 23 Dec 2008 at 12:06 am 42Zane Montgomery Hi Graham. Also skim Steve’s blog for logical operations since they’re used in image processing a lot. Something like: vec = [1 1 1 2 2 3 3 4 ] .. Zane. Less mess for you. Since I’m on a roll with vectorizing and using logical indexing. find(vector >90. 4 5 6]. and avoid using loops. soln=0. I also like solutions based on logicals since they very often handle whole vectors at a time. for n=1:size(vec.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. on 23 Dec 2008 at 10:14 am 43Rob S. sum(A(A>3)) Read the second line as “sum up the elements of A only where the elements of A are greater than 3″ I don’t want to duplicate what Loren’s and Steve’s blogs have covered about logicals. You could use a very simple ‘for’ loop to track how many times a number appears in your vector. but this method basically produces a “mask” vector of 1’s and 0’s the same size as A.Array Manipulation and Tricks | blinkdagger http://blinkdagger. Merry Christmas! Rob 44. and usually faster code. on 02 Jan 2009 at 3:55 am 45fawx hi 12 of 45 3/25/2011 1:43 AM . 42. Rob 45. @Graham. It tells the sum function which elements to include and exclude from its calcs. you could shoot the “vectorizer” at this problem. else end end 43. you can use.2) % gets the number of columns of the row vector if vec(n)==1 soln=soln+1.Matlab .1) to get the index of the first number greater than 90 in the vector. but there is a great post by Loren about indexing that I think covers logicals like this. …OR.

% now fill in your values b(1:2) = a(1:2).1). a=1:5 now insert 8 and 9 between 2 and 3 such that a= 1 2 8 9 3 4 5 thanks 46. inserts = [8 9]. b(5:end) = a(3:end). on 02 Jan 2009 at 9:37 am 46Rob S. but can be harder for multi-dimensional arrays. Then fill it in with your values.Matlab . Unfortunately.. b=[a(1:3) inserts a(4:end)] A few less lines. Great tips ! I am stuck with a problem related to sorting of a vector: I have following vector 13 of 45 3/25/2011 1:43 AM . Thanks for the help with logicals Rob 48. b(3:4) = inserts(:). Another way. using vector concatenation would be a = 1:5. % force whatever elements you want between segments of your 1-D array..com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. Something like: % create arrays to start with a = 1:5. inserts = [8 9]. @ fawx.s. Pre-assigning the size of arrays is good practice to improve the processing speed. b = zeros(numel(a)+numel(inserts). on 02 Jan 2009 at 10:48 pm 48fawx Thanks a lot Rob S.Array Manipulation and Tricks | blinkdagger http://blinkdagger. I would initialize a new 1D array (lets call it b) of size a + the inserts. how do i insert elements into an array by shifting the remaining elements to the right? eg . this will be a fairly manual operation. on 05 Feb 2009 at 8:14 pm 49rahul Hi Dan. Rob 47. HTH. p. on 02 Jan 2009 at 2:59 pm 47Zane Montgomery @fawx Rob’s method is extremely good for especially large arrays. disp(b). and Zane Montgomery that really helped a lot fawx 49.

more than if I used a for loop instead.10.111] Any such operator or do I need to create it myself? I’m not a programming guru so I’m not certain how to create this functionality in the most efficient way. 53.3 51. Thank you Rahul 50.3. I’m sorry if this has already been answered.11. 3. leaving a with only its’ first element intact: a == [1] b == [11. This save me a lot of time.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. vector = [1 1 0 0 0 1 1 1 0 1 1 1 0] What I want to know is how are ones grouped together ? In above vector they are grouped as = 2. on 12 Mar 2009 at 9:42 pm 51mohammed hey great work Quan thanks a lot this stuff is great 52.. on 02 May 2009 at 6:35 am 52Yo Hi guys.1). Here is my solution: k = 100. Do you guys have another suggestion? Thank you. on 05 Feb 2009 at 8:16 pm 50rahul In above the ans should be ans = 2. G = randn(k.. Gav=mean(reshape(G. on 02 May 2009 at 9:52 am 53Matt Hello everyone. My problem consist in averaging every 10 elements of an array (G) of size 100 and storing those averages. First let me say that I find this blog superb.Matlab . I’m sure someone has a great answer to a beginner such as myself ^^ 54. on 03 May 2009 at 11:18 pm 54nagendra to create logic gates by using matlab.Array Manipulation and Tricks | blinkdagger http://blinkdagger. but is there no built-in function that returns the elements you remove from an array? Example: a = [1.k/10)). but still I would like to improve it further if possible. 14 of 45 3/25/2011 1:43 AM .. Thank you for having it. Thanks in advance. 2 How can I sort my vector this way as to reveal the groupings .program.111] I want to return element 2 and 3 to create an array b.

sin((pi*t)/p). You can do more complicated stuff.^2 . b=a(a==11).111]. Jeppe We have a vector with some values given by a function.. 55. for instance if you want to remove the elements of a(:) equal to 11: a = [1. t M F Y = = = = 1:1:c.Matlab . Eg.11. Since you want to make a new matrix that is a column vector of many ‘a’ vectors. -Yo 56.1) where N is the N times you wanted above (aka ‘r’ in your code) 15 of 45 3/25/2011 1:43 AM . a(a==11)=[]. %We want our duplicated array to be of this size. just not the style that you want. Thanks in advance 57. . store them in another vector b(:). on 16 Jun 2009 at 7:12 am 57Zane Montgomery @Johan&Jeppe. { 1 0 1 0 0 1 } Our vector After the operation we want this result: 101001 101001 101001 101001 .com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. so we get a 2 dimensional matrix. I’m curious if the matrix you’re getting is 1-D or 3-D+? I would think it should still output as 2-D. F. your repmat should be repmat(M. What you could do is before removing some elements of a(:). repmat(M. I solved your example here: a = [1.c).111]. on 16 Jun 2009 at 5:25 am 56Johan.N. on 05 May 2009 at 9:14 am 55Yo Hi Matt. b=a(2:3).p) [r. Let’s call your vector ‘a’...11.Array Manipulation and Tricks | blinkdagger http://blinkdagger. a(2:3)=[]. .r. We want to duplicate this vector N times. But this doesnt give us a 2 dimensional matrix.c] = size(X). (N) times Our try: function Y = jail(X.

Its really usefull wesite. I need to know how to get the average of group of vectors…Lets say we have: A=[1 3 5] B=[4 7 1] C=[8 9 0] is there anyway to get the average of A. t M F Y = = = = 1:1:c.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. Hope that helps! -Zane 58. say. 60. on 20 Jun 2009 at 5:46 pm 59Nick Iversen How do I return the. Thanks for all of the tips. first element of an array expression without storing the expression into a temporary variable first? Eg result = first(expression). on 17 Jun 2009 at 2:26 am 58Johan..p) [r. you should check out the circshift command… it’s easy and you just enter the ammount that you want the vector shifted (you do however.^2 . %1:c works too. on 23 Jun 2009 at 9:06 pm 61bluray I wanted to insert the zero column vector in the matrix. %We want our duplicated array to be of this size.1). % rather than tmp = expression. I have this matrix [1 0 0 1 0011 1110 0 1 0 1] How do I convert it to [1 0 0 0 0 0 1 0 00001010 10101000 0 0 1 0 0 0 1 0] Thanks 62.. This will stack the matrix/vector on top of itself r times. have to convert the vector into a colum vector…): 16 of 45 3/25/2011 1:43 AM . repmat(M. on 23 Jun 2009 at 8:53 pm 60Tariq Hi .B and C?? 61. Jeppe Thanks Zane for the quick response.. I HATED shifting vectors! It’s not practical in most cases.r.Matlab .c] = size(X). result = tmp(1).Array Manipulation and Tricks | blinkdagger http://blinkdagger. by default it increments 1 every time sin((pi*t)/p). function Y = jail(X. this solved our problem.. Quan.. %changed F. on 25 Jun 2009 at 12:43 pm 62Circshifter Hi Quan. 59.

e.. for i=1:9. and places the last three elements % in the first three places! 63.. The array content has now changed.] 17 of 45 3/25/2011 1:43 AM ...Array Manipulation and Tricks | blinkdagger http://blinkdagger. 1 2 0 0 0. time=reshape(A. 1 2. To fill it in with what you wanted: for index = 1:200 myarray(index.] how do i transform the previous array to look like array =[1 2 0 0 0. on 30 Jun 2009 at 3:23 pm 64jose velez How would I create a 200 by 100 array size=250*100.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. due to typing error.. Array1 is an array of size 31 x 31 array Array2 is an array of size 31 x 21 I tried this but it only it only if the array is 1 dimensional. 66. end Example array= [1 2. t = [t 0].100). nirveda 64. on 06 Jul 2009 at 3:13 pm 65sf jose velez: To create 200 x 100 array: myarray = ones(200. but this will do the job quite nicely. on 27 Jun 2009 at 10:19 pm 63nirveda hey.99):(index*100). 201 202 203 ] 65. 101 102 103. thanks.Matlab . end There might be a better way than the for loop.3))' % This shifts vector "u" 3 places to the right...100) Now how would i filled the values of this array to [1 2 3 4 . u1 = (circshift(u'. its size has increased and values modified.i.. u = [1:10].250.. i’ve done a blunder by performing a set of operations on the wrong array.Is there any way to rollback this to the original state? or do i have to recode by rote? there’s really lengthy stuff preceeding it.. time=1:size.:) = (index*100 . on 12 Jul 2009 at 5:16 pm 66Jose The issue: I have two arrays filled with important data.

-5. winddir&lt. on 15 Jul 2009 at 10:30 am 70Budhie oops forget to fill my name…thx be4 guys.60. Somethings wrong with your ‘if’ statement. Try this out: %Array1 is 31x31 %Array2 is 31x21 ArrayNew=[Array2 zeros(31. %my array windspd = [1.2. winddir=180 &amp. south(180) &amp. wind direction in different array i want to calculate wind and direction data so i have north-south component which contain wind speed and north (+).10)] This concatenates a zero array of size 31×10 after you original 31×21 array2. 71.3. calculate north-south direction in winddir so i have north-south wind speed component north(0). i have problem how to calculate in array with 2 variabel &amp.19615. 67.135..210.4. Good luck! -Zane 68. -2.Matlab .=0 &amp.8284.120. winddir=90 &amp. -1. this very good matlab site i could need some help plz i have wind speed data (winspd) &amp.9] winddir = [30.5. east (90). winddir = cos(winddir*(pi/180)) end north_south = winspd . 69.south direction(-). You can play around with that. but let me show you a cool tip. 4.-0.Array Manipulation and Tricks | blinkdagger http://blinkdagger. Keep in mind I cant do it manually it has to be by MATLAB code because is a 31 x 31 array ( lots of numbers) Thank you for your efforts.6.86602.8.5. on 15 Jul 2009 at 10:23 am 69Anonymous % % % % % hi guys.7. west (270) correct me if i'm wrong with the if logic calculation i'm still new in matlab if winddir (find(winddir&gt. on 14 Jul 2009 at 8:04 am 67Zane Montgomery Jose. 1.225. but it is very specific on dimensions of each array.250.5] % many thx be4 :D 70. This can also be expanded/parametrized for an MxN array –> MxM array.34202. on 17 Jul 2009 at 7:38 am 71Zane Montgomery Hi Budhie. winddir=270 &amp. It looks like you’re just trying to convert the original winddir vector from degrees to radians and then taking the N/S (cosine) component of it? Two ways to do that: 18 of 45 3/25/2011 1:43 AM . i'new @ matlab.94974.* winddir %north-south component excpected result north_south = [0. but that’s not how I usually code in MATLAB.180. -5. on 14 Jul 2009 at 9:53 am 68Jose That worked Zane you are a genius.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.300] % % % % code not running yet.-4..

2.270) a = a*cosd(b-180) end end %expected results in 3x3 array a = [1.-2.250.6. but only on wind direction selected value and keep other value % how i can do that in matlab? if (b &gt. WinddirNS=cos(WinddirRad).8.5. but i still have problem doing operation in array.2.2.5.-5.-4.59807.3.3. MATLAB has built in capability to handle degree measurements: WinddirNS=cosd(winddir).4.82842. on 31 Jul 2009 at 1:53 am 73Budhie hmm the matlab code doesn’t properly display my code… a = [1. -Zane 72.225.Array Manipulation and Tricks | blinkdagger http://blinkdagger.73616. but only on wind direction selected value and keep other value in array a that not selected.(b&lt.250.9] %wind speed b = [30. i want to do something like this : a = [1.19615.sind().19615. thanks for the cool tips :D.-4.225.2. % and you're done! cosd()..6. hopefully it works for you too.7.82842.2..135.-2.2.9] 19 of 45 3/25/2011 1:43 AM .com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. WinddirRad=winddir*pi/180.*WinddirNS.94974. its works.120.-5. on 31 Jul 2009 at 1:51 am 72Budhie HI Zane.300] % wind direction % i want to do operation between 2 array.210.9] %wind speed b = [30. But even easier.tand() are your functions if your angle is in degrees.94974.2.8.(b=180)&amp.135.210.=90)&amp.60.60.-5.2. And to get your desired solution: north_south = windspd.300] % wind direction % i want to do operation between 2 array.59807.9] thx be4. -budhie73. That got me what you were looking for. yes i want to separete the wind component.120.-5.180.180.4. % how i can do that in matlab? if (b >=90)&(b=180)&(b<270) a = a*cosd(b-180) end end %expected results in 3×3 array a = [1.73616.7.Matlab .

on 31 Jul 2009 at 1:55 am 74Budhie sry if double posting…:D if (b >=90)&(b=180)&(b<270) a = a*cosd(b-180) end end 75.4 5. Alternatively I have seen in this very useful blog that values greater than / less than in a vector can be replaced by some. on 03 Aug 2009 at 7:26 pm 79Kalo How do I make a plot using h=pcolor for 210×1 matrix 80. on 31 Jul 2009 at 1:58 am 77Budhie else if (b >=180)&(b<270) a = a*cosd(b-180) 78. 5 and 2 twice consecutively in the above code. on 31 Jul 2009 at 1:57 am 76Budhie if (b >=90) & (b<180) a = a..4 2. I need some solution to extract these values at a certain min threshold to max threshold sequence.g. -budhie79.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. A = [ 2.2 4.4 5 2 4.4.g. on 31 Jul 2009 at 1:55 am 75Budhie if (b >=90)&(b=180)&(b<270) a = a*cosd(b-180) end 76. and I am looking to a solution for. I have a matrix for e. 20 of 45 3/25/2011 1:43 AM ..Matlab .3 1. thx be4.1 1.2 2. So. on 31 Jul 2009 at 1:59 am 78Budhie end end sry doesn’t display m if correctly… thx be4.4 5.3 1. -budhie74.5] now there appears 3.Array Manipulation and Tricks | blinkdagger http://blinkdagger.3 3. I am relatively new to Matlab. how can i do it to extract a particular pattern out of the code. and I see it as a pattern. but is there some solution that a block of values be replaced by some value for e.4 3. on 14 Sep 2009 at 1:57 am 80Malaika Hello. all values greater than 3 and less than 7 be changed to 0 in a vector.*sind (b-90) 77.4 5 2 6 8.

83. a(1) . on 11 Nov 2009 at 3:40 am 85packiyaraj hi everyone . b=a>0.5 .b(2). 1. 81. Can i do this without using loop with the help of array indexing or vectorising? 82.b(2). This website is really useful for us..5 . sum. How to group an array elements within range. -0. c(2) = min( a(2) . I will highly appreciate help in this regards. plz help me.1} great site by the way. a(3) .b(1). I’d recommend creating a new variable b to store you 0s/1s array.12.009.b(1).2.. c(3) = min( a(3) .1. /Malaika.b(3)). on 09 Nov 2009 at 2:44 pm 84lokise+o @ malaika some pseudocode : you could try to get indices find occurences of first value and sav index array idx = find(args(1)) and loop add + 1 after each cycle to the idxold+1 (6 13) => idxnew (7 14) and so on test next argument like this (you can take length. plz i need a help . a=[-1. a(1) .4 5 2 … testvector = vect(1:pos) hope it was helpful 85. on 21 Oct 2009 at 7:37 am 83Zane Montgomery Tim.b(3)). a(2) .12. Is there a efficient way to replace all values in the array that is greater than 0 with 1s and rest with zeros while maintaining the dimensions of the array. I want to do something like this c(1) = min( a(1) . 2} to a={ 0. a={ -1.2. but other than that it’s easy.b(3)). mean or numel of idx array) if mean(A(idxnew)) == val2 continue and increment pattern counter else break loop condition then would depend on flexibel vector length 3. on 20 Oct 2009 at 5:00 pm 82Tim hi. %note: zero gets mapped to a zero logical And you’re done! 2 quick notes: 1) B is an array of logicals 2) Make sure you’re using ‘array’ notation ‘[ ]‘.1.009.Array Manipulation and Tricks | blinkdagger http://blinkdagger.b(2).g. on 13 Oct 2009 at 4:53 am 81Anonymous I have 2 vectors say a = [1 2 3] and b= [4 5 6]. a(3) . -0. 0. e. a(2) . Zane 84.Matlab .com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. 21 of 45 3/25/2011 1:43 AM .b(1). Good luck.0. not ‘cell’ notation ‘{ }’ The cells is an array of 1×1 arrays and you’ll have to access each element individually to evaluate. 2]. 1. 0.

. x(1. &gt.. 1:2:end) % odd columns c = a(:.&gt. 100].e.can anyone plz help me in writing d code for it in matlab…?? Thanks in advance!! i/p: [1 3 4] o/p:[001.b) where x is your decimal number and b is the number of bits. and then you simply ask which are equal to one and destroy. Here’s an example: a = [1 2 3 4.Array Manipulation and Tricks | blinkdagger http://blinkdagger. on 12 Dec 2009 at 6:25 pm 86Daithi Hi .2). on 27 Jan 2010 at 3:05 pm 90Murphy how do you remove all the even numbers from a vector? 91.2) == 1) = [] The remainder function will flag all odd numbers with a 1.I am looking to convert a number to a 5 bit binary digit. on 15 Jan 2010 at 11:14 pm 89hcu hii all. on 03 Jan 2010 at 5:40 am 88krishh I have a array of dimension 5X16 ( 5 rows and 16 columns ) . 22 of 45 3/25/2011 1:43 AM . Try dec2bin(x. on 01 Feb 2010 at 11:43 am 91SPQR Murphey.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. a = [1 2 3 4 5 6] a(rem(a.011. GL.3) into binary and store in an array eg: Bin=[001. Zane 88. on 01 Feb 2010 at 11:52 am 92SPQR krishh. 92..1).5 6 7 8] b = a(:. on 15 Dec 2009 at 2:19 pm 87Zane Montgomery Daithi.Matlab . i hav a variable x=[1 3 4] i need to convert each value i. I want to separate it into 2 matrices having dimensions 5X8 and 5X8 with odd columns in one group and even columns in other group using matlab 89. 00101 Any help is appreciated. 2:2:end) % even columns The ‘b’ and ‘c’ equations would remain the same for any size a. x(1. Say 5 for example.100] 90. 86. dec2bin(5) ans = 101 I am looking for a 5 bit answer. x(1. Thanks 87. 011.

I need to form a new vector C that looks as follows. A=[1 3 5] B=[2 4 6] %Below is what C should be C=[1 2 3 4 5 6] 94. 96.2) == 0) = [] this will flag the even numbers for removal. then 4. Change: a(rem(a. Essentially do the opposite of my last example: A=[1 3 5] B=[2 4 6] C = zeros(1..Matlab . See Post #92 98.. A=[1 3 5] B=[2 4 6] %Below is what C should be C=[1 2 3 4 5 6] Thank you very much for you time 95. % initialize C C(1:2:end) = A % place A’s contents into C starting at 1.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. And a correction to comment #91 . on 26 Feb 2010 at 10:28 am 98Anonymous [199 0 185 0 214 0 63 0 0 188 0 207 0 158 0 89 186 0 201 0 194 0 63 0 23 of 45 3/25/2011 1:43 AM . etc. 93.Array Manipulation and Tricks | blinkdagger http://blinkdagger. I need to form a new vector C that looks as follows.2) == 1) = [] to: a(rem(a. on 26 Feb 2010 at 8:54 am 97SPQR sangeeta. on 12 Feb 2010 at 1:39 pm 93Hank I have to vectors A and B. on 12 Feb 2010 at 1:40 pm 94Hank I have to vectors A and B. on 17 Feb 2010 at 8:07 am 95SPQR Hank. C(2:2:end) = B % place B’s contents into C starting at 2. etc.length(A)*2). then 3. on 24 Feb 2010 at 2:18 am 96sangeeta [1 0 2 0 3 0 4 0] should becom [1 2 3 4] 97.I obviously removed all the odd numbers instead of the evens as asked.

the resulting matrix is [1 8 8 6 6 2] May I know how do we do that? Thank you 101.Array Manipulation and Tricks | blinkdagger http://blinkdagger.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. the resulting matrix is [1 3 8 6 9 2] If we have an index [1 2 1]. on 22 Mar 2010 at 2:47 am 102Stud Hello.from a matrix. Lets say the matrix is [1 3 8 692 589 7 6 3] If we have an index [1 1 1]. Again. 0 201 0 196 0 159 0 86 196 0 162 0 204 0 55 0] in this matrix all zeros should be deleted and resulting matrix should be [199 185 214 63 188 207 158 89 186 201 194 63 201 196 159 86] 99... I think you need to ask yourself why are you arriving at this position? What operation is forcing you to take such an action? The best solution would be to come up with a better algorithm that wont leave you with your back against the wall. the example above is quite symmetric.or any value .. how can i make from the following line: 555556666777889 Matrix like this: 155555 016666 001777 000188 000019 000001 24 of 45 3/25/2011 1:43 AM . padded set you will not be able to operate on it efficiently. on 01 Mar 2010 at 7:21 am 99SPQR There is a problem when attempting to “delete” the zeros . on 19 Mar 2010 at 8:01 pm 101sonal can u tell me how to convert the text file containing ascii code into binary number and store in array in matlab……….Matlab . on 16 Mar 2010 at 2:23 am 100bluray I need to select 2 elements from each column depending on the index. It would require initializing a new matrix and then filling it in as my posts above show. 100. 102. If there is not a square data set contained within a larger.

but you could use something like: x=[ 0 1 1 0 1]. It could be x(4:500) if those are all unchanged which saves lots of time. x=[ 0 1 1 0 1]. on 09 Apr 2010 at 4:46 am 107Matt Hi.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. on 01 Apr 2010 at 2:12 pm 106Zane Montgomery @ali I’m not quite sure I know what you’re getting at. x=[ 0 1 1 0 1]. x_new=[x(3) x(2) x(1) x(4:5)] This is very specific to this problem and gets trickier the more times elements need to be swapped. It works well for large segments of unchanged vectors like you see in the last vector element. I’ve got a problem. on 26 Mar 2010 at 9:29 am 103ali how I can change the position of one element without changing the size of the matrix. Has anyone ideas? Thank you! 103.. 106.Matlab .. I define a matrix like this for exampel: 25 of 45 3/25/2011 1:43 AM . If ‘a’ is your original matrix: a(3. Thanks 104.mathworks.com/videos/) this solution is very easy. on 28 Mar 2010 at 5:06 am 105waqas hi i want to remove the row of zeros for a matrix 1111 2222 0000 5555 to 1111 2222 5555 i tried too many way but couldnt find the right way. to x= [ 1 1 0 0 1].:)=[] will remove the entire third row. enjoy! 107. @waqas Thanks to a recently inspired video by Doug @TMW (http://blogs. Thanks 105. on 26 Mar 2010 at 9:35 am 104ali how I can change the position of one element without changing the size of the matrix.Array Manipulation and Tricks | blinkdagger http://blinkdagger. to x= [ 1 1 0 0 1].

this row contains no sixes &gt.6. even if one row contains 1.6.6. length(unique(row)) I highly recommend you figure out how each line does what it does.2] j = 1 1 6 6 1 4 ans = 3 &lt.Matlab .5.-.6.-.1.3. Best.6.5.&gt.1.6.-.2.6. on 09 Apr 2010 at 4:50 am 108Matt Sorry for the post.6.this row contains at least 1 six &lt.3. 109.5.2.3.6.2. What I want to do is count any number of occurences per row as one occurence.4. j = [1.-.2.this row contains no sixes &lt.&gt.6. 2 or 3 sixes it should only return 1. but i think the most elegant way is to use the ‘find’ command.this row contains at least 1 six &lt.4.6.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.1. Zane 110.6. &gt.6.1. What I am asking is whether there is any way to count each row in a matrix once if it contains at least one six for example.-.4] j = 1 1 6 6 2 5 6 3 4 Now if I do this: length(j(j==6)) I get 3 of course.this row contains at least 1 six &lt. on 14 Apr 2010 at 9:10 pm 110Gumah hi i want to add one column of zero whenever column of zero is exist 101101 202202 303303 505505 to 10011001 20022002 30033003 26 of 45 3/25/2011 1:43 AM .3. it seems to have trouble interpreting special characters such as > and <.2.6.4. on 13 Apr 2010 at 3:45 pm 109Zane Montgomery Hi Matt.4.Array Manipulation and Tricks | blinkdagger http://blinkdagger.2] [row. j = [1. I switched your ‘j’ variable to ‘a’ because ‘j’ is a MATLAB variable for the imaginary number sqrt(-1) a = [1.6.amount of rows containing at least one six 6 2 5 6 2 3 6 3 4 6 2 2 &lt..-..1. Multiple ways to do this.pseudofunction 108. 6) &lt. that is. I hope it is readable anyway.2. &gt.-.3.2. occurence(j. Is this possible? I hope it is clear what I want to do.col] = find(a==6).

7204 0.2189 -0.5).2063 -0.2324 0.6377 24.6842 0 0 0 292.2279 0..8610 267. on 03 May 2010 at 2:19 pm 113Zane Montgomery Emmi.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.3256 0.2791 0.9638 -0.3396 302.2098 -0. myVector(index) = [] 112.:.7017 0.7547 34.3348 0. However if I have a matrix after applying this.3315 0.3273 0.Array Manipulation and Tricks | blinkdagger http://blinkdagger. what would go on this line to plot both files on the graph? Thanks in advance! 115.2498 -0. on 30 Apr 2010 at 8:36 pm 112emmi Let’s say my matrix is sth like this: I wan to get rid of the zero lines. %index contains indices of elements within myVector which are greater than 5 index = find(myVector &gt. How can I use this.6668 0.2366 0.3255 0.2298 0.5573 29. 50055005 any body know how to do that ?? 111.1999 -0.1980 0 0 0 37.9092 -0.2159 -0. on 30 Apr 2010 at 8:19 pm 111emmi The code at entry number 24 is very nice.2333 -0.7989 0.9699 -0. Thanks in advance for the help.9639 -0.7279 0.5). the matrix becomes a row vector.1). 114. But I want to preserve the matrix.3317 0.3267 0.6331 0.9478 256.7641 0. I am wanting to plot both of these files on the same graph for the functions below: x=0:0.7276 26.:.3346 0.3249 0 0 0 0.3219 0.3564 0. -0.2740 0 0 0 0.2302 0. is there a difference? Let’s say I have 3 of these matrices in A(:.1044 27. 5). on 05 May 2010 at 1:43 pm 114Drew Hi.3022 23.3153 0. How can I do that? Secondly.3701 273.2879 0. myVector = [10 0 0 1 12 3 0 0 4 5 1 12 0 0].1645 0 0 0 0 0 0 113.2234 0.9597 -0.2441 0.How to remove all elements greater than 5 from a vector.2031 0.9472 0 0 0 0.3449 0.*sin(x-0.9832 -0.9826 296.6209 0.1570 263.2) and A(:.5975 286.1262 29. y1=sin(x+0.7218 25.9965 265.2156 -0.:.9938 -0. A(:. 27 of 45 3/25/2011 1:43 AM .3663 304.3) and I want to get rid of the zeros from all of these matrices.2138 -0.7109 0.3334 0.Matlab . and let the matrix stay as it is? 24. y2=90.2090 0 0 0 -0.1:3*pi.9474 -0.3019 0.6314 0. if I have similar matrices in a multidimensional matrix. the most recent posts in the comment area show this pretty well.2147 0.0925 29. on 09 May 2010 at 2:53 am 115sonny Hi.2959 0.3223 0. Try those out and get back with any other questions..9378 -0.

:)=[].. for i=2:2:100 A(i.:) = []. A(2:2:end. %i want to make this flexible or how to make a simple loop calling the indicesToRemove? The output A will have the size of [50x100]. Fado. But my matrix is quite big and how I can remove all the even row without specifying all the rows index? A=eye(100).. for i=2:2:100 A(i. answer should be [4 5 9 10 13 15 18 19 6 11 14 4 3 2] how can i reach this answer? 118. indicesToRemove = [2.:)=[].10. Thanks in advance. I have a question on removing multiple rows from a matrix. 28 of 45 3/25/2011 1:43 AM . 117. I knew we can remove rows that we want but specifying all rows index.6. I would do it like this: A=eye(100). Instead of A=eye(100).. on 10 Jun 2010 at 9:17 am 116fado hi. end You directly call the rows and annihilate A = eye(100). Instead of using the ‘for’ loop.4.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d...8.. on 28 Jun 2010 at 2:40 am 119Bertus oh btw.. as bertus did.. you simply index into the matrix all at once. vector=matrix(:).But my array is big (4461X1) can you help me plz? Thanks . and Bertus: You want to use logical indexing. on 28 Jun 2010 at 10:01 am 120SPQR Sonny. 120.Matlab . end 119.Array Manipulation and Tricks | blinkdagger http://blinkdagger.. 116. . on 13 Jun 2010 at 2:41 am 117jyoti sahu prob:[4 5 9 10 13 15 18 19 6 9 11 14 4 6 9 10 3 6 7 2 2] this is 1D array…………. on 28 Jun 2010 at 2:35 am 118Bertus @sonny/fado.. i want to remove multiple lines (7*i) index . an easy way of converting a matrix to a vector: matrix=magic(5). 100].

1. on 29 Jun 2010 at 1:40 pm 121Jason Greetings: A=[1:0.2 2.7.2:2:end).5.8 2.1.5.8 1.5 3.--.2 3.2 1.1. 121. Im not entirely sure about fado’s case whether he wants to annihilate every seventh row.4 3.=B)).3 % &lt.. For columns you call them A(:.7.7.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. It keeps going for higher dimensions.3 1. I would either call: A(1:7:end.1.5.1].1. C of course is a vector of values in which A >= B: C = 1 1.first element in the array associated with the index that is not included u 1.9 29 of 45 3/25/2011 1:43 AM .-.1. For odd rows you would write A(1:2:end.1.9 3 3.1.8 3.1.8 2.:)..2 2.first element in the array associated with the index that is not included 2.1 2.9 2 2.1.1.1.3 2.9 2 2. or A(1:7.3 2.3 1. or seven rows in a block.1.1 1.4 % &lt.1 3.7 3. C=A(find(A&gt.1.1.6 3.:) = [].8 1.Matlab .1.1.1. B=[1.1 1.9 4 What I need however is to include the first element in the subsection that is not included with the find. Keep in mind that my solution works for any size matrix to get rid of the even rows.5.3 3.Array Manipulation and Tricks | blinkdagger http://blinkdagger.:) = [].7.1.1 2.1.2 1. So for example: C = 1 1.1:4]'.1.

Let’s say for example the above code returns the indicies: idx = 1 2 3 4 10 11 12 16 17 18 idy = 5 6 7 8 9 14 15 So at index 1-4. 3 3.B).2 3.. so in my example above: idx = find(A&gt. idy = find(A&lt.This is X 30 of 45 3/25/2011 1:43 AM . the element in A is >= than in B. 10-12.6 3.7 3. on 30 Jun 2010 at 1:28 pm 123Jason find() of course returns the indicies that match.This is X 10 11 12 13 &lt.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.Array Manipulation and Tricks | blinkdagger http://blinkdagger.8 3.the first element in each group where A < B.1 3.4 3.--.. on 30 Jun 2010 at 9:01 am 122Zane Montgomery yup.=B). And great site by the way!!! 122. What I need is to return the first index in each excluded group . lost.5 3. Can you make a smaller simplified example? 123.--. Please email if you can help. and 16-18.9 4 I’m having some trouble explaining this so I hope it make sense.3 3. returns the indicies from A where A is greater than B. So for example: idx = 1 2 3 4 5 &lt.Matlab . dunno what your ‘group’ and ’subsection’s are referring to. Call this situation X.

clc. l=numel(a). b(k)=a(1). clear all.. That’s an easy fix regardless. close all. k=1. on 09 Aug 2010 at 12:42 pm 127Andre My question How can I get every data at every 5 numbers in a vector.. Thanks. 32 of 45 3/25/2011 1:43 AM .Array Manipulation and Tricks | blinkdagger http://blinkdagger.Matlab . For example: A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 .. same as 1:1:2000 sol=A(1:4:end). I need the matlab code for duplicate elimination in an array… kindly help me. (hundreds of numbers) And I have a data every 5 datas. a=[1 1 1 3 6 6 5 7 7 7 7 ]. couldnt get …. on 16 Aug 2010 at 8:39 am 128Zane Montgomery Andre. It looks like your solution starts at 1 and then gets every ‘4′ after that. (hundreds of numbers) Thanks a lot for all 128..com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. 127. %creates your vector from 1-2000 (as an example). This can be done quite easily. you want to sample your column vector every n index values. like: Result: Result = 1 5 9 13 ... on 16 Aug 2010 at 10:14 pm 129anita Hi all.. A=1:2000. %starts at 1 and captures every 4th value after that until end of vector A 129. not 5.i tried using the following code.

i have been slogging over filtering an array and a cellarray of strings. 130. %insert code here Thank U. b(k)=a(i). else k=k+1.. for i=2:l for j=1:k if a(i)==b(j) break. How can I go about doing that in Matlab? Any help is much appreciated! 132.Array Manipulation and Tricks | blinkdagger http://blinkdagger. on 18 Aug 2010 at 10:45 am 130SPQR anita. break end end end display(b). display(b).com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. on 08 Sep 2010 at 12:55 am 133Tannistha Thanks a lot. So if Azimuth>90 and Azimuth<135 then Azimuth = 135. a=[1 1 1 3 6 6 5 7 7 7 7 ]. 133. on 01 Sep 2010 at 3:16 pm 131Dingo I have a one column vector that contains a series of azimuthal angles between 0 and 180 ex. b = unique(a) 131. Azimuth= 0 10 156 26 120 56 180 etc… I would like to replace all the values between 90 and 135 with 135.Matlab ... on 02 Sep 2010 at 7:42 am 132Zane Montgomery Here ya go Dingo: Azimuth(Azimuth<135 & Azimuth>90)=135. i did something to get the position of 33 of 45 3/25/2011 1:43 AM .

. on 09 Sep 2010 at 10:58 pm 135Zane Montgomery Tapos. Zane 138.Matlab . Lets Say vec=[45 8 2 6 98 55 45 -48 75] 137. 2) To get 1 (column) vector of the matrix use: x=v(2. on 13 Sep 2010 at 10:14 am 137Zane Montgomery John.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. How do you remove all even integers out of a vector. To get 1 point of the matrix use: x=v(2.. good luck. then i need to modify some of the elements using conditional statement depending upon the position of the elements. Try this trick: vec(~mod(vec. 2) To get 1 (row) vector of the matrix use: x=v(:. S. 2.in an array and had no idea how can i keep only those elements whose position was recorded and your vector tutorial gave me the idea thanks a lot 134. 2) etc… Just keep playing around with those and look at other comments/questions to hopefully find your answer. S. the colon ‘:’ mean ‘all’. 2) To get a 2D depth array of the matrix use: x=v(:. 2. can anybody help me? 135. 136. or depth value. column.Array Manipulation and Tricks | blinkdagger http://blinkdagger.8. Do you have data or a more detailed need? If you want to call an entire row.. on 11 Sep 2010 at 1:27 pm 136John.2))=[] I encourage you to figure out what that does! Best. Lets say you have an 8×8x8 3D matrix like you described. :. the elements that will stay .8). how can i extract and change data from a multi-dimensional matrix? i can create a matrix containing all zeros or ones using v=ones(8. on 09 Sep 2010 at 4:38 am 134tapos hi. :. on 18 Sep 2010 at 5:30 pm 138rudra 34 of 45 3/25/2011 1:43 AM . you’ll have to be a bit more specific.

g. 122.0. x53.0.5. 24. x14. then fill it with a new value every iteration try this: xx=[] %preallocate your answer vector 'xx' %for loop code here for yy=42 %this is your calculated value that changes every iteration xx=[xx yy]. y41. 9. y54. x54. y52.0. how do we create arrays as the for loop proceeds? 139. x22.Matlab .5. 24. y34. x24. 122.0.5. y31.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. 59 is 59 seconds after the hour/minute. 2252. 126. 22. y24. y51.0 ] [ y11. 1227. y32. 1840. y15. TS0 < TS1 == True). y13. x55 ] ys= [ 159. 122. 4 ] [ x11.5. on 21 Sep 2010 at 10:28 am 140Jason Greetings all: Imagine I have two 2-dim arrays: xs = [ 59. 23. 4. 122. x35. 2945. I’m using the minutes and seconds only for sake of brevety (e. x31. y35.5. 121.0. y53. 22. 123. y12. etc) 35 of 45 3/25/2011 1:43 AM . x25. x51. 2445. x21. 124.5. 123.Array Manipulation and Tricks | blinkdagger http://blinkdagger.0. y14. y42.5. y44. 21. 25.5. x32. 23. y43.5. x12. Zane 140. y23. 23. the values of an array are appended? lets say we have a nested function.0. 121. 123. x42. 1727. x15. y21. 1340.5. 9. 24.g. x41. x52. 123. %this is the key code here that appends the new value to the end of the old xx vecto end %end of for loop good luck. x13.5. y55 ] Assume the first column of each matrix is a timestamp which can be compared to each other (e. 1452.5. 4. 26. y25.0. 1727 is 17 minutes 27 seconds after the hour.5. x33. If you want to start from a blank array. x44. y45.5. x23.0. on 20 Sep 2010 at 12:19 pm 139Zane Montgomery I think I know what you’re talking about Rudra.0.5. 125. y33.5.. x34.. 22.5. how is it that as we run our for loop. 21. 124. y22.5. 124. x45.0. 22. 23. x43.

x42.5. x15. y43. 1727 21. % element in y changes.0.5. 24. y43. x15.5. 26. where the first timestamp column will survive and the remaining columns will be joined in one of two ways: 1. 2252. y42. on 21 Sep 2010 at 3:27 pm 141Zane Montgomery Jason. 25.5. 1727. 4. 4. y13. x13. ] [ y11. % element in y does not change.5. y23.5. 24. y12. 124.5. nm. 1452 122. y43. 23.5. y42.5. 25. x23.5. 123. y44. 122. x14. 4. x22. 4. 22. x14.0.5. 124. x12. 126. 1727. 24.5.5. x15. 23.5 9. y22. x24. x24.5 126.0 23.5. x13.5 22.0 ] [ y11. 25. 123. 121. 4. x12. x44. x15. x43. 23. 21. x23.0 4 ] but this is not complete of course because it does not actually “join the arrays”. 1227. are you missing a column in ys?).. x does not y21. I’m not sure how you’re comparing your matrices or how you get the desired matrix value you want (one confusion is your ys matrix is 5×4. So the result should look like this: nm = [ 159. 123. 124.5. Second way is to join the arrays if both elements have changed. 122. % element in y does not change. 122.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. x25. It looks like you need some help creating the logicals of the comparator and then apply that to concatenating 2 matrices in different ways depending on the logical value. x22. x12. So the result should look like this: nm = [ 159. x25. 125. I’m not sure how your values are ‘changed’ in the following sentences: 36 of 45 3/25/2011 1:43 AM .0. 123.0. but your variable ys matrix is 5×5 while all other inputs are 5×5 too. 25. % element in y changes. x does ] 2.Matlab . x does not y41. 122. y14. but essentially I’ve been able to return a matrix to (kind of) match case 1: [ 159 124. x45.0. y43. First way is to join the arrays if either element has changed. i’m trying to go through the logic here but it’s a bit confusing not knowing the problem or the same level of detail you do. 24. 26.0. 24. x14. 1452. y13.0.5.5. % element in y changes.5. 123. y44. 124. y42. 22.5 123.5.0. 9. 125. x13. x does not x21. Summary. 22.5. y44.0 24.5.5 122. I’m new in MATLAB and appeal to the community for help! 141. y12.0 124. y14 x21.5.5.Array Manipulation and Tricks | blinkdagger http://blinkdagger. 9. 26. 124. x12. y44 ] I’ve made far too many attempts to post code here. x does x41.. 21. 2252 22. 122.0. The return value must be a third matrix.0. y24.5 23. 26.5.5. y42.5.0.0 123. x13. 1227 121.0.5 125. x14.5.0.5.0.

24.8 are the values from matrix y (note the values differ in each row because the y values change at time 159 and 1227). on 22 Sep 2010 at 5:16 am 142Jason Thanks for the response . but in the meantime.).5 at time 159 (first row) to 121.5. nm should have two rows: 159.this is a bit difficult for me to explain. Y does not change again until time 1452 to price 122.5.mathworks. So Y changes three total times. price Y changes from 124. on 22 Sep 2010 at 7:58 am 143Zane Montgomery I’ll check that out and edit this post if/when i get a chance. 123.5..” Could you give an example using 3×3 matrix perhaps? ttys. While Y is changing from time 159. 122.. For sake of argument. 4. ORD. So the two methods I outlined are ways to join the series in ways suitable for regression analysis.5.5 at time 59 (first row) and does not change until it changes to price 21. 126.5. 125. you can post on the MATLAB Central (http://www. 142. winsor. First way is to join the arrays if either element has changed. 1227. 143. So if we were to put time times in order (column 1 of both matricies).com/matlabcentral/newsreader/) forums where magnitudes more people will view your 37 of 45 3/25/2011 1:43 AM . etc. Column 1 is the timestamp from matrix y.5. the times would be: 59 from x < the x value from this timestamp persists at each y value change below until at least the next x change at time 1840 159 from y 1227 from y 1340 from y 1452 from y 1840 from x 2252 from x 2445 from x 2945 from y The only time we record a price is when one or the other change from the previous value. 4. 24. use the first two columns of the matricies . “1.” “2. X starts at price 24. 25. x is not changing.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.5 are the values from matrix x (note the value is the same in both rows because the value did not change between time 159 and 1227).5 at time 1727 (second row). The securities trade infrequenty without a “closing price” like stocks so we cannot compare them arbitrarily by lining them in up in series. Second way is to join the arrays if both elements have changed.5. In the meantime.5.5 at time 1227 (second row). Columns 2 .Array Manipulation and Tricks | blinkdagger http://blinkdagger.5. So at this point.Matlab .column 1 representing a timestamp and column 2 representing the price. 26. The goal of the project is to use the joined matrix to run robust regressions (OLS rejection. 26.5. but here goes: The arrays represent price series for derivative (credit default swaps) securities.5. 124. 121. 25.5. Columns 6 .

. 148... thanks for the response… 145. 38 of 45 3/25/2011 1:43 AM . on 24 Sep 2010 at 8:27 am 144Jason Ha ha I did and got no response… I’ve come to a workable solution altering the program elsewhere. how can i do it.. on 06 Oct 2010 at 9:42 am 150Trey You are awesome. Please help me. this is shaps.. Like during the first iteration the values shd be stored in A0 and next iteration it should be in A1 and so on. 147.. i want the value of ‘A’ to be stored during each iteration of if loop in the form of A0. on 27 Sep 2010 at 3:44 am 148Shaps hi. on 29 Sep 2010 at 5:56 am 149Mukil Hi. I used this for loop below.:).:). i mean A0 should hav first set of data then A2 next set of data. end But. index out of bounds because size( Then.5). i hav a array of strings stored in a variable ‘A’ within a if loop.........5 using the index.:)..Matlab . Mukil 150. %randomly generate 4-by-5 matrix indx = round((size(d)-1)*rand(1. this variable is getting overwritten everytime. I mean first time when it enters the if loop it shd be stored in A0 next tym when it enters it shd be in A1 and so on. I have a doubt. How can i do it? can you pls help me. This is shaps. on 25 Sep 2010 at 6:03 am 145Fess I. for eg [1 2 3 4] should become [1 0 3 0] Thank you. end Do you have any solution or idea on how I can get it to work. on 27 Sep 2010 at 2:57 am 146Shaps hi.Array Manipulation and Tricks | blinkdagger http://blinkdagger. this variable is getting overwritten evytime. Hi. 149. but it does obtain a row from the matrix.. I hav a array of strings stored in a variable ‘A’ within a if loop... Here d = rand(4. I want it to be stored seperately.. % finding indices of the matrix % Here am trying to randomly obtain any row from the matrix for i = 1:size(d) indxr = d(indx(i). I hav a array of strings stored in a variable ‘A’ within a if loop. How to replace alternate elements of a row vector with some value. can you pls help... this variable is getting overwritten everytime.A1.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. question 144. on 27 Sep 2010 at 2:59 am 147Shaps hi. how can i do it? can you pls help. I got this error message: ??? Attempted to access d(5. but it is same row every tim for i = 1:size(d) indxr = d(indx(i)...A2. This is SHAPS..1)+). I want it to be stored seperately. I have been trying to selectively pick a row from a matrix dimension of 4. The basic idea is to randomly select 146.

The input is a 16*1368 matrix and the output is a 500*1 matrix. on 18 Nov 2010 at 12:18 pm 153luke Jacob. I have an algorithm that finds out the best features in a matrix and gives out the output as the indices of the input data that were selected as best features. 3 9 15 21] Is there a shortcut for this? 153.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. For example: Input Col 1 2 3 4………………… A=[ 100 20 3 4 5 6 7 8---->row1 9 10 11 12 13 14 15 16----->row 2 24 67 21 38 42 53 54 90]—> row 3 Output: [1 2]—> column indices Now I want a matrix C such that C= [100 9 24 20 10 67] Please help me out ! Thanks and regards.Matlab . on 26 Oct 2010 at 1:51 am 151Christopher Alain Jones great post all round! very helpful especially the interesting debates 152. If first row is given (say r)..Array Manipulation and Tricks | blinkdagger http://blinkdagger.. 39 of 45 3/25/2011 1:43 AM . I want to compare the indices obtained as the output to the input indices and if they match I want to copy the rest of the row in a separate matrix. then your matrix is: A=c*(1:numel(c)). on 14 Dec 2010 at 2:41 pm 155Kajal Hello All. Suppose that the first column is c (given). 151.'*r. on 13 Dec 2010 at 10:30 am 154basu how to display the maximum and minimum group elements in a duplicate vector using matlab code if the element present in the max group display corresponding max group elements and if the element present in the min group display corresponding min group elements how?Help me 155. Your matrix is composed of multiples of first row (or column). 2 6 10 14. then: A=(1:numel(r)). on 08 Nov 2010 at 1:06 pm 152Jacob I need to make the matrix: [1 3 5 7. 154.

B(n))']. i have a 3D Matrix such as 40 of 45 3/25/2011 1:43 AM . Any advice on how to do it? thanks! 159. 24 67 21 38 42 53 54 90]. C=[].6154 0. %generate C as an empty matrix for n=1:length(B) C=[C.9169 0. How I can do x3 = [0. B=[1 2]. 161.9355 0..1763 0.9218 0. what I want is B=[1 1 1 1 1 2 2 2 2 2 3 3 3 3 3]. %Add a new row to C using the column of A defined by index B end C %prints out C Should work! good luck. on 24 Jan 2011 at 7:24 am 160Leandro Hi… I have two vectors.9355 0..Array Manipulation and Tricks | blinkdagger http://blinkdagger.6154 0. on 03 Feb 2011 at 9:05 am 161Felix hi. on 22 Dec 2010 at 10:32 am 156Zane Montgomery Kajal. 9:16. on 20 Jan 2011 at 12:49 pm 158iaj4 Hi all. on 12 Jan 2011 at 1:37 pm 157Wolfhantich hello everybody.9169 0. x2 = [0. I’m going to assume you only need help making matrix C and you know how to build your input/output matrices? In the code. -Zane 157.1763].com/matlab/matlab-tips-and-tricks-on-manipulating-1-d.7919 0.8936].7382 0.Please let me know thanks 160.4103 0. on 22 Jan 2011 at 6:26 am 159jay Hi I have a vector with both +ve and -ve values and the index vector. how can I do that? thx 158.9218 0. I do have a vector with real data that was colected every 5 minutes. Kajal 156. initial matrix A=[1 2 3]. I have some A (input) and B (output) matrices already populated which hopefully you can do already. While sorting the vector again according to -ve to positive I would like to keep track of the index also and arrange it accordingly. Both are taken from a large vector.8936]? I don’t want to use ‘for’… Thanks.7919 0. For example: x1 = [0. i want to have a matrix with data every one minute. A=[ 100 20 3 4 5 6 7 8.4057 0. I have to do this I need to add value 3 to all odd values of vector x. B contains the arbitrary number of indices in ‘A’ you want to put into C.Matlab .. A(:.4103 0.7382 0.4057 0.

com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. c=[1 2 3. Thanks for the post. New Comer to this page. 163.&gt.. on 05 Feb 2011 at 11:02 am 163Anonymous 41 of 45 3/25/2011 1:43 AM .1) = 12 34 QQ(:. ‘find’ just works for 2D arrays . QQ=cat(3.0 2 3..w.8) to find my position for point 8.. c(z'.2) = 56 78 now i want to use [r c]=find(QQ.:)=[] c = 1 0 2 2 3 3 Answered this question by reading this page alone. on 05 Feb 2011 at 11:01 am 162Anonymous @anuj on 12 Mar 2008 at 3:06 am 10 QUESTION How can I remove rows in a matrix that have third element in the column 0 Input123 230 023 020 Answer should be123 023 ANSWER &gt.q) QQ(:.:.Matlab .&gt.&gt.Array Manipulation and Tricks | blinkdagger http://blinkdagger.:.0 2 0] c = 1 2 0 0 2 3 2 2 3 0 3 0 &gt. is there is possibility for 3D arrays? 162. z=find(c(:.3)==0) z = 2 4 &gt.2 3 0..

Array Manipulation and Tricks | blinkdagger http://blinkdagger. as a part of class project. on 08 Feb 2011 at 11:03 am 167Ted I’ve been trying to delete all the columns of a HUGE matrix that contains all zeros: info: my matrix size is (60. my query is let a=[1 2 3.. on 06 Feb 2011 at 1:37 pm 164vijay hi. displays the element of 6. 4 5 6. I am trying to implement linear convolution by my own.:) 167.0 2 3. So.e 4 5 6.. how to make it display the entire row/column .com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. i. my query is let a=[1 2 3.2 3 0. on 07 Feb 2011 at 8:21 pm 166vijay the command to be used is a(2. what command should i use? 166. i.3)==0) z= 2 4 >> c(z’.e 4 5 6.Matlab .7 8 9] a(6).4000000) which is pre-allocated 42 of 45 3/25/2011 1:43 AM . on 06 Feb 2011 at 1:39 pm 165vijay hi. So. 4 5 6.I wish to display only the second row. I am trying to implement linear convolution by my own. as a part of class project.0 2 0] c= 123 230 023 020 >> z=find(c(:.7 8 9] I wish to display only the second row. >> c=[1 2 3.:)=[] c= 123 023 164. what command should i use? 165. but I would like to know .

76. 77. i have a matrix A=[70.Matlab . 80.7+8+9] Thanks 172. 75. tried: matirx(:.2. 79. 81. 81. 173. question: how do i get rid of all the columns from 2500000 . 7 // frequency of each distinct element please help me to do this task 171. 77. example: i have data on the 2500000 and below…after the 2500000th column . 80. 75. newmatrix=matrix(:. 4. thx colm 170.ones(1.5. 78.7. 73. on 01 Mar 2011 at 3:17 pm 173Liz 43 of 45 3/25/2011 1:43 AM .8. 75.4. 81 81.9] I would like to have this matrix: B=[1+2+3.6.3))*A. 80. 72. 77. 1. 75. 81. 72. 1. 4. i can’t even copy the old matrix with a new one without getting the “out of memory error”. and i need code for converting m*m matrix to m*1 row matrix 169. 3.. 81] i have to find the frequency of repeated elements as well as distinct element list like b = 70.2500001:end)=[]. 79. 79.4+5+6. 2. 75. on 27 Feb 2011 at 4:11 pm 171mansur Dear all. 76. 4. on 22 Feb 2011 at 7:57 am 169Colm how do i change all the 0’s in a matrix to the value 1. 1. 71. 79. 80. on 25 Feb 2011 at 5:23 am 170Ashutosh Gupta Hi All. i need a matlab code which can store pixel values in a register or a 1D array. 78. 79.3.com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. 77. 78. 81 // array of distinct elements freq = 1.i only have zeros.1:2500000). Please help. do you have any idea how could I accumulate every three member of an array and save it t o another array: Lets assume: A=[1. 73. 73. 78. 74. thanks! 168. 81. 78. 79. 76. 79. 80.. on 28 Feb 2011 at 2:31 am 172mansur The answer: B= kron(speye(3). 3. 76. on 21 Feb 2011 at 2:34 am 168chitra hi.Array Manipulation and Tricks | blinkdagger http://blinkdagger.4000000 without getting the “out of memory” error. 7. 79. 74. 71.

. I need to have those new vectors as a part of one matrix. for example.. Hi there! Is there a function that would enable me to find the proportion of values in an array that are above or below a certain value? Thanks. 175. I got this problem: How do I repack the one column vector(with 200 elements) into 50 column vectors with 4 elements each? Also. Any help would be greatly appreciated. on 17 Mar 2011 at 5:04 am 175kyrzi dear all.Array Manipulation and Tricks | blinkdagger http://blinkdagger. Liz 174. but i want a specific number of 0s (and 1s). all arrays must have 4 zeros and 2 ones. on 15 Mar 2011 at 1:23 am 174Mar Hi all.Matlab . i want to make a 6×6 matrix with 0s and 1s. Leave a Reply Include MATLAB code in your comment by doing the following: <pre lang="MATLAB"> %insert code here </pre> Name Mail (hidden) Website 44 of 45 3/25/2011 1:43 AM .com/matlab/matlab-tips-and-tricks-on-manipulating-1-d. Thank you.