How to solve this in matlab?

1 view (last 30 days)
Amir Hamzah UTeM
Amir Hamzah UTeM on 26 Apr 2011
Hi,did someone know how to convert this equation in matlab?i know this is easy since matlab have build in function.but i cant figure it how to do that in matlab,still new in matlab..
a=1...nth value
b=1...nth value
Xab = X in pattern a and pattern b
Kab = K in pattern a and pattern b
Matt Fig
Matt Fig on 26 Apr 2011
So is Walter's solution what you are looking for? If not, and Paulo's is not either, please give a simple example, such as:
X = [2 3 4 8];
K = [7 5 6 9];
What do you want from these two vectors? Or do you need to work on arrays, such as:
X = [2 3; 4 8];
K = [7 5; 6 9];

Sign in to comment.

Answers (2)

Paulo Silva
Paulo Silva on 26 Apr 2011
%pre-allocate the vectors for Xab and Kab
% can't decode this %?Xab.Kab
for a=1:na %a=1...nth value
for b=1:nb %b=1...nth value
Xab(a+b-1)=X; %Xab = X in pattern a and pattern b
Kab(a+b-1)=K; %Kab = K in pattern a and pattern b

Walter Roberson
Walter Roberson on 26 Apr 2011
I am not at all certain I am interpreting the question correctly, but possibly:
sum(X(:) .* K(:))
Walter Roberson
Walter Roberson on 27 Apr 2011
sum of a matrix multiplication? Hmmm, possibly. The arrays are an acceptable shape for that.

Sign in to comment.


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!