Transfer Array into another array

I have two arrays
n=input
A=randi([0 20],1,n);
B=randi([0 10]',1,n)';
How do I make an array C that has the values of A as the first row and B as the first column, then fill the rest as the product of A*B.
like a multiplication table.

5 个评论

What have you done so far? What specific problems are you having with your code?
n=input('Enter a number between 5 and 10: ');
while n<5||n>10
fprintf ('Invalid Number!! number has to be GREATER THAN 4 and LESS THAN 11\n')
n=input('Enter a number between 5 and 10: ');
end
A=randi([0 20],1,n);
B=randi([0 10]',1,n)';
I have made an Array A as first row
and Array B as first Column
I just dont know how to create an array C with the numbers from array A and B. I googled a bunch and I cant find a noob friendly solution. I am in comp apps 1 so im sure the solution is simple.
Array C being size n x n
Yes, the solution is simple. Some hints for you:
You can concatenate variables with the [ ] notation. E.g.,
[x,y] concatenates the variables horizontally
[x;y] concatenates the variables vertically
You can transpose a vector from row to column (or vice-versa) with the .' operator, or just ' if you know the variable is real. E.g., if x is a real row vector, then x' will be a real column vector.
You can multiply two variables element-wise with the .* operator. If one of these is a row and the other one is a column, then the result will be a 2D matrix with the element-wise products as the elements.
See if you can experiment and work with the above to come up with the parts you want, and then see if you can use the [ ] notation to put them all together into the final matrix you want. Come back and ask more questions when you have trouble with your progress.
Thank you so much... your little paragraph summarize 120 minutes of lecture.

回答(1 个)

Looks like James Tursa has resolved your query. You can use built-in functions like horzcat and vertcat to achieve the same thing.
I would recommend you to check out the free MATLAB OnRamp Course to get started with the fundamentals of Matlab.

此问题已关闭。

标签

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by