Appending Arrays at the END!

I have three arrays of sizes:
1) A[]=839063*1; (ZEROS)
2) B[]=4393*1; (some values) {example [0.1 0.2 0.3 . . . . ] random values }
3) C[]=191*1; (some values randomized)
Here I need to multiply every element of C[] with EACH element of B[]. like
for i= 1:length(B)
ANS = B(i) * C; { example 0.1 * [1 2 3 4 5 6 7 8 9 . . . . . 191] like this I have to do 4393 times}
END
Then I have to store all these values in array A[] and I have to append these values at the end of the array after each for loop.
Currently I am using the below algorithm to resolve this, and is not working. Can you please tell me a better way to do this????
for i = 1:length(A)
for j = 1:length(B)
for k = 1:191
A(i)=B(j)*C(k);
end
end
i=i*(191);
end

 Accepted Answer

James Tursa
James Tursa on 12 Dec 2018
Edited: James Tursa on 12 Dec 2018
E.g.,
A = B * C.'; % outer product
A = A(:); % turn into column vector

9 Comments

Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in
the second matrix. To perform elementwise multiplication, use '.*'.
This is the message shown, Please note that the arrays are NOT of same sizes.
Then the matrices are not the sizes you told me. What is the output of this:
size(B)
size(C)
Sanchit Sharma
Sanchit Sharma on 13 Dec 2018
Edited: Sanchit Sharma on 13 Dec 2018
Apologies for misunderstanding!
size(A)=839063
size(B)=4393
size(C)=191
Here is the explanation of my problem:
array A =[ (1st element of B) X C() ; (2nd element of B) X C(); (3rd element of B) X C(); . . ............................. (4393th element of B) X C() ];
total elements in A = 4393 X 191 = 839063;
This is exactly what I want.
James Tursa
James Tursa on 13 Dec 2018
Edited: James Tursa on 13 Dec 2018
No. Please run the code size(B) and size(C) and paste the output here.
>> size(PULSES1212) % This is Matrix A()
ans =
839063 1
>>
>> size(Height) % This is Matrix B()
ans =
4383 1
>> size(PULSES) % This is MATRIX C()
ans =
191 1
And this:
PULSES1212 = Height * PULSES.';
This is the error coming.
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in
the second matrix. To perform elementwise multiplication, use '.*'.
+1 , it works !
I got it Thanks a lot!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!