Get all the values from a two (for loop)

1 vue (au cours des 30 derniers jours)
Ali Tawfik
Ali Tawfik le 9 Juin 2020
I am running two for loops with means it run 5*5..
Later the size of x will be (1,5) however; the x runs more than that!!!
Can I obtain all the values of the x ...I mean all the values running even in matrix
clear all;
clc;
d=1:5;
for i=1:5
g=1:5;
for j=1:length(g)
x(:,i)=d(i)*2;
end
end

Réponse acceptée

KSSV
KSSV le 9 Juin 2020
Modifié(e) : KSSV le 9 Juin 2020
clear all;
clc;
d=1:5;
g=1:5;
m = 5 ; n = 5 ;
x = zeros(m,n) ; % initilization
for i=1:5
for j=1:length(g)
x(i,j)=d(i)*2;
end
end
The above can be obtained without loop.
x = repmat(d'*2,1,5)

Plus de réponses (1)

madhan ravi
madhan ravi le 9 Juin 2020
Wanted = ones(numel(1:5),1).*((1:5)*2)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by