フィルターのクリア

How to hold on values in ''Vector" with the continuity of the loop

1 回表示 (過去 30 日間)
abdullah al-dulaimi
abdullah al-dulaimi 2022 年 12 月 26 日
コメント済み: Voss 2022 年 12 月 26 日
I have this example:
for t=20:10:30
for i=900
a=t+i
end
end
I want result to be (Vector a):
a=
920
930

採用された回答

Voss
Voss 2022 年 12 月 26 日
t = 20:10:30;
i = 900;
a = t.' + i
a = 2×1
920 930
  2 件のコメント
abdullah al-dulaimi
abdullah al-dulaimi 2022 年 12 月 26 日
by Loop
Voss
Voss 2022 年 12 月 26 日
Or, if you must use loops:
t_all = 20:10:30;
i_all = 900;
nt = numel(t_all);
ni = numel(i_all);
a = zeros(nt*ni,1);
idx = 1;
for t = t_all
for i = i_all
a(idx) = t+i;
idx = idx+1;
end
end
disp(a)
920 930
Or:
t = 20:10:30;
i = 900;
nt = numel(t);
ni = numel(i);
a = zeros(nt*ni,1);
idx = 1;
for t_idx = 1:nt
for i_idx = 1:ni
a(idx) = t(t_idx)+i(i_idx);
idx = idx+1;
end
end
disp(a)
920 930
Or:
t = 20:10:30;
i = 900;
nt = numel(t);
ni = numel(i);
a = zeros(nt*ni,1);
for t_idx = 1:nt
for i_idx = 1:ni
a((t_idx-1)*ni+i_idx) = t(t_idx)+i(i_idx);
end
end
disp(a)
920 930

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by