could anyone help me to solve the issue
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
jaah navi
il 28 Ott 2018
Risposto: Walter Roberson
il 28 Ott 2018
how to remove the partitions which contains {3},{4} and {3 4} in the following partitions of set{1 2 3 4} The 15 partitions of set {1 2 3 4}:
{1 2 3 4}
{1 2 3} {4}
{1 2 4} {3}
{1 2} {3 4}
{1 2} {3} {4}
{1 3 4} {2}
{1 3} {2 4}
{1 3} {2} {4}
{1 4} {2 3}
{1} {2 3 4}
{1} {2 3} {4}
{1 4} {2} {3}
{1} {2 4} {3}
{1} {2} {3 4}
{1} {2} {3} {4}
0 Commenti
Risposta accettata
Bruno Luong
il 28 Ott 2018
A = SetPartition(4);
NotWanted = {[3] [4] [3 4]};
matchfun = @(s) any(cellfun(@(x) isequal(s,x), NotWanted));
b = cellfun(@(c) any(cellfun(matchfun,c)), A);
A(b) = [];
partdisp(A)
You'll get the following
The 5 partitions of set {1 2 3 4}:
{1 2 3 4}
{1 3 4} {2}
{1 3} {2 4}
{1 4} {2 3}
{1} {2 3 4}
0 Commenti
Più risposte (1)
Walter Roberson
il 28 Ott 2018
Learn how to use for loops and while loops. Learn how to index cell arrays. Learn how to use if statements. Learn how to use "break". Learn how to add an element to an existing array or remove an element from an existing array.
Hint: isequal() can compare arrays of different lengths.
Important programming advice:
Get the code to work first. Even if it means using for loops nested 8 deep. Get it to work.
If you don't know a fancy short way to write the code, write it the long way. Get it to work. Don't worry about making it fancy unless it is taking all day to execute.
As it is now, you are being held up for months at a time trying to find fancy ways to write code that will be executed a small number of times, and that is blocking you from making progress on your project.
Get the code work first. You can always go back to make it nicer looking after you have gotten right through to the end of the task.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!