Info

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

Could anyone help me how to solve the issue in the following code.

5 ビュー (過去 30 日間)
jaah navi
jaah navi 2019 年 8 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
code:
A=partitions(3)
partdisp(A)
for d=1:length(A)
for e=1:length(A{d})
rows = A{d}{e}
end
end
In this code i am using partitions function where it is inbuilt function already defined in matlab.
when i executes the above code it gives the result .
But i want to have the result in such a way the code should should execute only for the first four combination and the final combination {1} {2} {3} should not appear.
Could anyone please help me on this.
  2 件のコメント
John D'Errico
John D'Errico 2019 年 8 月 19 日
編集済み: John D'Errico 2019 年 8 月 19 日
The only function that I know of by the name of partitions is the one I wrote and placed on the file exchange. If so, then it is not built into MATLAB. In fact though, I did find a second code named partitions, also on the file exchange. It includes a code named partdisp.
Again, it is NOT part of MATLAB, not a built-in functionality. You have it because you downloaded it.
jaah navi
jaah navi 2019 年 8 月 19 日
My mistake.I downloaded both partitions and partdisp from the matlab.
with respect to the above code,it executes and gives me the following result
rows = 1 2 3
rows = 1 2 rows = 3
rows = 1 3 rows = 2
rows = 1 rows = 2 3
rows = 1 rows = 2 rows = 3
but i dont want to have the last partition
rows = 1 rows = 2 rows = 3
The code should display only the first four partition.
Could you please help me on it.

回答 (1 件)

John Wheater
John Wheater 2019 年 8 月 19 日
How about a semicolon after rows = A{d}{e} rows = A{d}{e};
to suppresss the default output
Then for i = 1:4 ...
  2 件のコメント
jaah navi
jaah navi 2019 年 8 月 19 日
the semicolon can be after the end of command rows = A{d}{e};
I just removed it inorder to observe the process in the command window.
here the code by itself should not display the last combination.
As you have stated for i=1:4 coudl you please help me to explain it.
John Wheater
John Wheater 2019 年 8 月 19 日
Sorry, I just thought you simply wanted the first 4 rows of the the displayed 'rows' variable.
I'd be happy to look further if you post a sample piece of runnable code.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by