Get all the values from a two (for loop)

6 ビュー (過去 30 日間)
Ali Tawfik
Ali Tawfik 2020 年 6 月 9 日
回答済み: madhan ravi 2020 年 6 月 9 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by