Trying to put values from one array into another

4 次查看(过去 30 天)
I've created the below array and want to take a value from it, divide it by the size of said array and then populate a row in a new array with that value.
So for the 1,1 value of the array (1) I want to divide by 5 (to give me a value of 0.2).
I then want to put this value in a new array, but populate the whole first row with it, like so:
0.2 0.2 0.2 0.2 0.2
I then want to repeat this the values (1,1 through 5,1) to give me a new array of:
0.2 0.2 0.2 0.2 0.2
2/5 2/5 2/5 2/5 2/5
3/5 3/5 3/5 3/5 3/5
4/5 4/5 4/5 4/5 4/5
1 1 1 1 1
I'm just not entirely sure how to do this, I thought maybe setting up a blank array of zeros would be a good start then add to that?
As well as this I then want to repeat the process in the horizontal direction i.e. for (1,1 through 1,5)
Thanks in advance
array = [1 1 1 1 1; 2 2 2 2 2; 3 3 3 3 3; 4 4 4 4 4; 5 5 5 5 5];
array
n=size(array,1);
n
blank=zeros(n,n);
figure
imshow(blank);
for i = 1:1:n
value=array(i,1);
value
divided=value/n;
divided
end

回答(1 个)

Peng Li
Peng Li 2020-3-28
A(:) ./ size(A, 1) * ones(1, size(A, 1));
If I understand what you said correctly, the above script will give you what you need I think.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by