Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I want to store all the outputs in a single matrix and also i want to select all the combination for which c has minimum and maximum value.

1 回表示 (過去 30 日間)
Jasvinder Singh
Jasvinder Singh 2019 年 6 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
for a=1:5
for b=5:8
for c=1:20
if mod(a+b,c)~=0
t=[a,b,c]
end
end
end
end
I want result in the following form
t =
1 5 4
1 5 5
1 5 6
1 5 8
1 5 9
and so on
Kindly help me

回答 (1 件)

Jan
Jan 2019 年 6 月 6 日
編集済み: Jan 2019 年 6 月 6 日
result = zeros(5 * 4 * 20, 3); % Pre-allocate with maximum size
count = 0;
for a = 1:5
for b = 5:8
for c = 1:20
if mod(a+b,c) % ~=0
count = count + 1;
t(count, :) = [a,b,c];
end
end
end
end
t = t(1:count, :); % Crop unneeded memory
  1 件のコメント
Jasvinder Singh
Jasvinder Singh 2019 年 6 月 6 日
The code is working correctly. But it is showing all the results; I required the combinations in which c has minimum value and maximum value; I am not interested in the midle ones. So, kindly give some directions for this.
Thanks

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by