Filling an array with color points
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ursula Trigos-Raczkowski
le 1 Avr 2022
Commenté : Les Beckham
le 1 Avr 2022
I am trying to create an array (matrix?)
I have J curves I am plotting and I want to create a vector of color values.
The matrix will have J rows and 3 entries per row. the First entry will be 0 the third entry will be 1. The second middle entry will be (i-1)*1./J. where i is my counter in the for loop.
```
j = 34; g = 3;
A = zeros(j,g);
for i= 1:j
A(:,i) = 0 (i-1)*1./j 1;
end
disp(A)
```
So I want something like, if j=34 , A=[0 0 1; 0 1/34 1; 0 2/34 1; ... ; 0 33/34 1;]
Thank you for your time and help.
0 commentaires
Réponse acceptée
Les Beckham
le 1 Avr 2022
Modifié(e) : Les Beckham
le 1 Avr 2022
j = 34; g = 3;
A = zeros(j,g);
A(:,3) = 1; % put ones in the third column
A(:,2) = ([0:j-1]/j).'; % fill in the second column (' makes it a column)
format rat
disp(A)
2 commentaires
Plus de réponses (1)
Voss
le 1 Avr 2022
I think this is what you were going for:
j = 34; g = 3;
A = zeros(j,g);
for i= 1:j
A(i,:) = [0 (i-1)/j 1];
end
disp(A)
And you can do it without the loop like this:
A = [zeros(j,1) (0:j-1).'/j ones(j,1)];
disp(A)
2 commentaires
Voir également
Catégories
En savoir plus sur Data Type Identification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!