- I have to make my code draw all 52 cards from a deck and return what I have drawn each time, so the result would be f.x.:
- You have drawn the Ace of hearts.
- You have drawn the 10 of spades.
- You have drawn the 2 of spades.
- …. and so on until every card is gone from the deck.
- This is my code so far:
- A=randperm(52)
- for i=1:length(A)
- %sort
- switch i
- case {1,2,3,4,5,6,7,8,9,10,11,12,13}
- sort='hearts';
- case {14,15,16,17,18,19,20,21,22,23,24,25,26}
- sort='spades';
- case {27,28,29,30,31,32,33,34,35,36,37,38,39}
- sort='clubs';
- case {40,41,42,43,44,45,46,47,48,49,50,51,52};
- sort='diamonds';
- end
- %spil
- if A==1;
- spil='ace';
- elseif A==14;
- spil='ace';
- elseif A==27;
- spil='ace';
- elseif A==40;
- spil='ace';
- elseif A==11;
- spil='jack';
- elseif A==24;
- spil='jack';
- elseif A==37;
- spil='jack';
- elseif A==50;
- spil='jack';
- elseif A==12;
- spil='queen';
- elseif A==25;
- spil='queen';
- elseif A==38;
- spil='queen';
- elseif A== 51;
- spil='queen';
- elseif A==13;
- spil='king';
- elseif A==26;
- spil='king';
- elseif A==39;
- spil='king';
- elseif A==52;
- spil='king';
- else spil=num2str(A);
- end
- disp(['You have drawn ',spil,'of ',sort])
- end
- But it returns everything in a bundle.
- What am I doing wrong?
MATLAB: What is wrong with the code? (Matlab)
cardshomeworkrandom
Best Answer