Trying to put values from one array into another

6 vues (au cours des 30 derniers jours)
Adam Kerry
Adam Kerry le 28 Mar 2020
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

Réponses (1)

Peng Li
Peng Li le 28 Mar 2020
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.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by