Skip to main content
1-Visitor
May 12, 2014
Solved

Programming/Matrices

  • May 12, 2014
  • 3 replies
  • 4672 views

If I have two vectors each with one column and 15 rows and I want to take the minimum of each row of the two vectors and make that a new vector is that possible?

Best answer by LucMeekes

Sure David,

Here's a solution.

MinRow.png

Now instead of the two fixed vectors, you can call MinRow with any set of vectors you like: MinRow(FirstVector, SecondVector)=...

You will get an error if the length/size of the vectors are unequal.

Success!

3 replies

LucMeekes23-Emerald IVAnswer
23-Emerald IV
May 12, 2014

Sure David,

Here's a solution.

MinRow.png

Now instead of the two fixed vectors, you can call MinRow with any set of vectors you like: MinRow(FirstVector, SecondVector)=...

You will get an error if the length/size of the vectors are unequal.

Success!

25-Diamond I
May 12, 2014

min() cannot be vectorized, otherwise it would be a oneliner.

But we can define an auxiliary function using min() which then can be vectorize and does the trick without programming.

12.05.png

Heavenly1-VisitorAuthor
1-Visitor
May 13, 2014

Thanks for the quick replies!! Both solutions work great. Since I am not very savy with programming or with using functions that are not on the basic toolbar I really apppreciate the help. I do have another question related this topic.

If I have three vectors A, B,C. Vector A is composed of lets say 5 entries which are either "red" or "blue". Vector B is all 1's and Vector C is all 2's. I want to return a 4th Vector that returns 1 if the entry in Vector A is red and returns 2 if the entry in vector A is blue.

Thanks.

25-Diamond I
May 13, 2014

What would you need vector B and C for?

Its always better to attach a worksheet so we don't have to type in all from scratch - helps to motivate providing a solution 😉

Here is a way to achieve what you described and to achieve what I think you wanted:

13.05.png

Heavenly1-VisitorAuthor
1-Visitor
May 13, 2014

WE,

Attached is the file I am trying to get working. For example on pg. 7 I am trying to solve for Pn. I tried making a vector with 15 entries of 0.44 but that didnt work. A solution for this problem will fix the others in the worksheet. Thanks.

Dave