how to increase a column with every for loop

3 ビュー (過去 30 日間)
Prakhar Modi
Prakhar Modi 2019 年 8 月 2 日
編集済み: madhan ravi 2019 年 8 月 2 日
Hello Everyone,
let say for example I have two variables y with 25 data and x1 with 25 data. so for 1st iteration I will calculate x1*y. Than for second iteration I have to include a new variable x2 and than I have to calculate x1*y and also x2*y. and similarly with every iteration I have to calculate till x6*y.

回答 (2 件)

madhan ravi
madhan ravi 2019 年 8 月 2 日
編集済み: madhan ravi 2019 年 8 月 2 日
With loop:
N = 7;
xy = zeros(numel(x),N);
xy(:,1) = x .* y;
for k = 2:N
xy(:,k) = xy(:,k-1) .* y;
end
Without loop:
XY = cumprod([x .* y, repmat(y,1,N-1)],2);

Torsten
Torsten 2019 年 8 月 2 日
column = x.*y;
iter = 0;
while iter < 6
[calculate new x-vector];
column = [column ; x.*y];
iter = iter + 1;
end

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by