主要内容

Results for


Given a tic tac toe board:
1 represents X
0 represents empty.
-1 represents O
It is X's move. If there is an immediate win possibility, choose a square for an immediate win. Otherwise return 0.
Return absolute index of the square of choice. If multiple square are valid, return them in order.
Example:
Input a = [ 1 0 1
-1 1 0
0 -1 -1]
Output wins is [4 8]
Can anyone explain it in detail?
I'm confused with the sentence I marked ans bold style.
Thanks a lot~~~
I've written a valid answer to the last Cody problem, but it is not even close to the best answer. I have no idea how they made this short answer. To unlock it I need to solve another Cody question, but there are none left... :(
Anybody know how to unlock the last question?
Hi,
i'm "solving" number 30 cody's problem.
I think to solve that whit sortrows function.
If I have a z vector:
j = sqrt(-1);
z = [-4 6 3+4*j 1+j 0];
my funtion is:
function z = complexSort(z)
z(2,:)=sqrt(real(z).^2+imag(z).^2);
z=sortrows(z',-2);
z=z(:,1);
end
End it return the result
z =
6.0000 6.0000
3.0000 - 4.0000i 5.0000
-4.0000 4.0000
1.0000 - 1.0000i 1.4142
0 0
The question is: why imagine part in input is positive e sortrows trasform it in negative?
best regards
Marco
Hello all,
Please explain good MATLAB programming practice methods. It will help to the guys who are new to programming like me.
Previously I used
for i=1:10
after following some suggestions from this answers pages I learnt to use
for i1=1:100
This is the good way to write programs.
Like this, as a professional programmer, please mention some good programming practice techniques.
It will useful to all!
Capital letters are obtained by capitalizing the LaTeX command for the lowercase version. Capital letters in grey are exceptions which have no LaTeX commands. For example, to produce a capital chi simply type X (this also applies for the lowercase omicron).
When two versions of the lowercase letter are available, a var prefix can be added to obtain the second version. For example, the two versions of epsilon are \epsilon and \varepsilon.
--------------------------------------------------------------------------------------------------------------------------------------------------------
The code used to generate the table:
greeks = ...
{'ALPHA' 'A' '\alpha'
'BETA' 'B' '\beta'
'GAMMA' '\Gamma' '\gamma'
'DELTA' '\Delta' '\delta'
'EPSILON' 'E' {'\epsilon','\varepsilon'}
'ZETA' 'Z' '\zeta'
'ETA' 'H' '\eta'
'THETA' '\Theta' {'\theta','\vartheta'}
'IOTA' 'I' '\iota'
'KAPPA' 'K' '\kappa'
'LAMBDA' '\Lambda' '\lambda'
'MU' 'M' '\mu'
'NU' 'N' '\nu'
'XI' '\Xi' '\xi'
'OMICRON' 'O' 'o'
'PI' '\Pi' {'\pi','\varpi'}
'RHO' 'P' {'\rho','\varrho'}
'SIGMA' '\Sigma' {'\sigma','\varsigma'}
'TAU' 'T' '\tau'
'UPSILON' '\Upsilon' '\upsilon'
'PHI' '\Phi' {'\phi','\varphi'}
'CHI' 'X' '\chi'
'PSI' '\Psi' '\psi'
'OMEGA' '\Omega' '\omega'};
h = figure('units','pixels','pos',[300,100,620,620],'Color','w');
axes('units','pixels','pos',[10,10,600,600],'Xcol','w','Ycol','w',...
'Xtick',[],'Ytick',[],'Xlim',[0 6],'Ylim',[0,4]);
% Loop by column and row
for r = 1:4
for c = 1:6
el = (r-1)*6 + c;
% Title
text(c-0.5,5-r,greeks{el,1},'Fonts',14,'FontN','FixedWidth',...
'Hor','center','Ver','cap')
% Color cap latter in grey or black
if strcmp(greeks{el,2}(1),'\')
clr = [0, 0, 0];
else
clr = [0.65, 0.65, 0.65];
end
% Cap letter
text(c-0.5,4.87-r,['$\rm{' greeks{el,2} '}$'],'Fonts',40,...
'Hor','center','Ver','cap','Interp','Latex','Color',clr)
% Lowercase letter/s (if two variants)
if iscell(greeks{el,3})
text(c-0.75,4.48-r,['$' greeks{el,3}{1} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
text(c-0.25,4.48-r,['$' greeks{el,3}{2} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
% Latex command
text(c-0.5,4.3-r,['\' greeks{el,3}{1}],'Fonts',12,'FontN','FixedWidth',...
'Hor','center','Ver','base')
else
text(c-0.5,4.48-r,['$' greeks{el,3} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
text(c-0.5,4.3-r,['\' greeks{el,3}],'Fonts',12,'FontN','FixedWidth',...
'Hor','center','Ver','base')
end
end
end
% Print to pdf
export_fig greeks.pdf
The link to export_fig.
And here is the link to the pdf on scribd: http://www.scribd.com/doc/159011120/Greek-alphabet-in-latex
[INDEX]
--------------------------------------------------------------------------------------------------------------------------------------
[MOTIVATION]
Why should we use markups in the body of our questions?
The answer is a question: which of the two versions is more likely to be understood in a glimpse and has more chances to be answered by our readers?
.
< Consider the following question >
I have a vector of weights W=[10,20,30,50,23434,1,2.4,2] and a matrix A=rand(100,8) and I would like to find the row-wise weighted sum of A. I am proceeding in the following way: B=zeros(size(A)); for c=1:numel(W) B(:,c)=A(:,c)*W(c); end B=sum(B,2); Somehow I get huge numbers can you please help?
.
< Now, consider its formatted version >
I have a vector of weights W = [10,20,30,50,23434,1,2.4,2] and a matrix A = rand(100,8) and I would like to find the row-wise weighted sum of A.
I am proceeding in the following way:
B = zeros(size(A));
for c = 1:numel(W)
B(:,c) = A(:,c)*W(c);
end
B = sum(B,2);
Somehow I get huge numbers can you please help?
--------------------------------------------------------------------------------------------------------------------------------------
[AKNOWLEDGMENTS]
In alphabetical order by nickname, thanks for their suggestions to:
Walter Roberson
--------------------------------------------------------------------------------------------------------------------------------------
[LOG]
  • 06 Aug 2011, 13:17 BST - created and added boldface.gif
  • 06 Aug 2011, 14:59 BST - added italic.gif
  • 06 Aug 2011, 18:58 BST - added index section
  • 07 Aug 2011, 00:03 BST - added code.gif and tutorial series section
  • 07 Aug 2011, 01:50 BST - added monospaced.gif, numlist.gif, bullist.gif and hyperlink.gif
  • 13 Aug 2011, 14:27 BST - added motivation section
  • 18 Aug 2011, 01:44 BST - added aknowledgments section and link to wish-list
--------------------------------------------------------------------------------------------------------------------------------------
[TUTORIAL Series]
Do not forget to read the Markup help (located on the top-right corner of the Body pane)
Vote on Wish-list for MATLAB Answer sections my post if you think that a tutorial section on top of Answers could be useful.
Now, I am still a novice when it comes to programming. I believe MATLAB is definitely a great programming tool, one that I can play with, particularly, when I have free time.
I would love to hear from all answerers, what are the ways that can make one proficient in this field?
This topic is for unexpected or bizarre or humorous references to MATLAB. Specific citations would be appreciated.
Please post the easter eggs that you have found so far if they aren't already posted by someone else.
Let's try to make a good Matlab easter egg list because it seems that there isn't one.
What should be posted:
  • Unexpected but intentional behaviour
  • Special things that the programmers left for us to discover
  • Extra code inside a function that can be used for other purposes
  • Hidden pictures and audio clips
What shouldn't be posted:
  • Repeated Easter Eggs, if someone already posted it please don't repeat
  • Bugs in functions that cause trouble and might be fixed in later versions
  • Matlab games that come with the program unless they aren't mentioned in the documentation (the games are in the other demos, try the xpbombs and fifteen, you can even see the code for both games)
What is the best way to learn MATLAB at home without a tutor?