0

I have the matrix like this

Table1 = [A B ; C D ; E F] 

and the vector:

V = [a ; b ; c] 

How to get the multiplication of second column of matrix M to get the answer as below?

ans =[aB ; bD; cF] 

Currently I'm doing,

Table1; d=length(Table1(:,2)); for i = 1:d ans(i,:) = sum(Table1(i,2)) .* V'; end 

The only way I can think would be using loops but I couldn't get the answer as I wish. Could anyone help me?

2 Answers 2

5

Hi If you really want ans =[aB ; bD; cF]. You are looking for the elementwise product of the second column with the vector.

THat would be:

product = Table1(:,2).*V; 

or if you want the same order (normally that shouldn't matter but who knows)

product = V.*Table1(:,2); 

Table1(:,2) adresses the second column. And the dot (.) means elementwise.

Otherwise MATLAB can process Matrix multiplication and others just as you would write them on paper.

Sign up to request clarification or add additional context in comments.

2 Comments

@LuisMendo Well mathematically you could have sth like gradient (d/dx, d/dy, d/dz). So by multiplying it first you get (d/dx x, d/dy y, d/dz z) or by multiplying it second you would have (x d/dx, y d/dy, z d/dz). Which would change a lot because you would have to do additional derivation. Because I am a physist I have to take sth like that into account :D
Oh, I see. I've always considered that "gradient after/before" thing as a notation trick, rather than a real product, but you're right. In this case, perhaps .* could be overloaded into something non-commutative
0

If you know that you want to multiply the second number of every vector

Table1 = [A B ; C D ; E F] 

you can use the downsample command

newTable=downsample(Table1, n) % with n=2 or the step you want newTable= [B ; D; F] V = [a ; b ; c] 

then you can use the multiplying vectors to get your results

x = newTable.*V x =[B*a; D*b ; F*c] 

3 Comments

You could easily just use Table1(:,n) instead of using downsample(). ALso he doesn't want to multiply a constant to each value but a vector. so your resulting x is wrong your code (if a=V in OP) is still right (except the double use of a)
@Minion you are correct i overlooked it , i will alter the answer
and you have a typo in newTable (2nd code block) you have D, F but need D; F

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.