Matrix dimensions must agree

I am performing a multiplication in the following equation but, I had this error because the sizes of (resultx) and (etae) are different. The size of (resultx) is 10001x10001 and the size of (etae) is 1x50. Is there a way to let this multiplication work in matlab?. I highly appreciate any help. thanks
Iph1=pinc*(resultx)^2.*(etae/h*v)

Answers (1)

Image Analyst
Image Analyst on 7 Apr 2015
No, sorry but there is not. Why do you think it should work?
Which of the 10001 by 10001 elements do you want to multiply by which of the 50 etae elements?

12 Comments

Naema
Naema on 8 Apr 2015
Edited: Naema on 8 Apr 2015
All etae with the middle of the 10001x10001 is the most important part. But, generally, can we multiply mXN by 1XN?
You can multiply (m x N) * transpose(1 x N), giving you a (m x 1).
So , I can not get a result of size mXn?? a 2-d plot??
I think you need to let us know what you are doing in more detail. There may be solutions for you (e.g., interpolation?) that are appropriate, but we have no way of knowing based on what you have told us so far. E.g., this would work, but does it make any sense at all for your problem?
bsxfun( @times, (your m x N matrix), (your 1 x N vector) )
We really have no clue whether this makes sense or not for your problem, even though MATLAB will give an answer for it. That is why we need more detail from you.
"can we multiply mXN by 1XN?" - No, not with usual matrix multiplication. Anyway you don't even have that. Your N is 50 and your m would be 10001, but your resultx is 10001x10001, NOT 10001x50. Be careful about what dimensions are what values because you're being inconsistent now.
Naema
Naema on 8 Apr 2015
Edited: Naema on 8 Apr 2015
I got what I want now, I want to multiply resultx by only one value from etae.I want to access only the first value of etae and the last value of eate separately. can I do it like this:
Iph1=pinc*(resultx).^2*(etae(1,1))/h*v) % for first value
and,
Iph2=pinc*(resultx).^2*(etae(1,50))/h*v) % for last value
and, did I square (resultx) correctly? pinc,h, v, etae are single values. resultx is (mXn)
That should work because etae(1,1) or etae(1,50) are just scalars, not arrays. I also assume pinc, h, and v are scalars. By the way, you can use the keyword "end" to get the last element in a row or column
lastValueInColumn1 = etae(end, 1);
lastValueInRow1 = etae(1, end);
thanks. I want to make sure what I am doing is correct. I wrote it like this:
Iph1=pinc.*(resultx).^2.*etae(1)/h/v;
I want to make sure especially with the dot after resultx. When I remove that dot , the value of the result changes. Should I keep or remove this dot?
h/v is different than h*v you know.
And etae(1) is the upper left element - the same as etae(1,1). And etae(50,1) is the same as etae(50) but etae(1,50) is not the same as etae(50).
Other than that I really have no idea what your equation is supposed to be or do.
my equation has only h and v in the denominator, the rest are in the nominator. all of the inputs are scalars except resultx is a matrix mXn and etae is a vector 1X50. I want to access only the first value of etae to be multiplied with the other inputs.Is the following right?
Iph1=pinc.*(resultx).^2.*etae(1)/h/v;
Yes, but just to be clearer, since etae is a 2-dimensional matrix, I'd use etae(1,1) instead of etae(1). It will just be a lot more clear what you intend. Then you can use
Iph1=pinc*(resultx).^2*(etae(1,1))./h*v) % for first value
or
Iph1=pinc*(resultx).^2*(etae(1,1))./h/v) % for first value
whichever you want. They give different resuls. I say that neither one is clear and you should use use parentheses around the h*v or h/v to make it crystal clear what you want. Here is what they are equivalent to:
Iph1= v .* pinc*(resultx).^2*(etae(1,1))./h) % for first value
or
Iph1=pinc*(resultx).^2*(etae(1,1))./(h*v)) % for first value
Naema
Naema on 8 Apr 2015
Edited: Naema on 8 Apr 2015
thanks :) I see. I used this:
Iph1=pinc*(resultx).^2*(etae(1,1))./(h*v))

Sign in to comment.

Asked:

on 7 Apr 2015

Edited:

on 8 Apr 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!