Get all the values from a two (for loop)

2 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2020-6-9
编辑:KSSV 2020-6-9
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)

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by