How to do the following two for loop?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How to do the following two for loop?
i=0.1:0.1:0.9 ;
M=[1 1 1 1 1 1];
first outer loop :
In the 1st inner loop Assign i=0.9 on the first element, then in the 2nd inner loop Assign 0.8 on the first element till 0.1
then 2nd outer loop
In the 1st inner loop Assign i=0.9 on the 2nd element, in the 2nd inner loop Assign 0.8 on the 2nd element till 0.1
.
.
and so on .. till the 6th outer loop
0 commentaires
Réponse acceptée
Torsten
le 9 Fév 2023
You mean
i=0.1:0.1:0.9 ;
M = [i.',ones(numel(i),5)]
?
Plus de réponses (2)
Image Analyst
le 9 Fév 2023
Don't call variables "i" -- it's the imaginary constant.
Try this, for example to multiply M by 2
vec = 0.1:0.1:0.9
M = [vec 1 1 1 1 1]
result = M * 2
% Or via a for loop
for k = 1 : numel(vec)
result(k) = 2 * M(k);
end
To learn other fundamental concepts, invest 2 hours of your time here:
0 commentaires
Image Analyst
le 10 Fév 2023
"assign i=0.9 on the first element, then assign 0.8 on the first element till 0.1"
Try this
for k = 1 : 9
result(k) = (10 - k) * 0.1;
end
result
2 commentaires
Image Analyst
le 10 Fév 2023
OK, so did you do it? Again, don't use "i" as the name of your variable. That is something everyone here advises against.
for k = 1 : 9
result(k) = (10 - k) * 0.1;
end
M = [result, 1 1 1 1 1]
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!