主要内容

Results for


Join our celebration of the 20th anniversary of MATLAB Central community! You are invited to enter 2 contests - A Treasure Hunt and a MATLAB Mini Hack - to have fun and win prizes.

How to Play

  • In the Treasure Hunt, complete 10 fun tasks to explore the ‘treasures’ in the community.
  • In the MATLAB Mini Hack, use up to 280 characters of MATLAB code to generate an interesting image. Simply vote for the entries that you like or share your own entries to gain votes.

Prizes

You will have opportunities to win compelling prizes, including special edition T-shirts, customized T-shirts, Amazon gift cards, and virtual badges. Your participation will also bump up our charity donations.

Ready to participate?

Visit the community contests space and choose the contest you’d like to enter. Note that:

  • You need a MathWorks account to participate. If you don’t have a MathWorks account, you can create one at MathWorks sign in .
  • Make sure you follow the contests (click the ‘follow the contests’ button on the top) to get notified for prize information and important announcements.

For the full contest rules, prizes, and terms, see details here .

We hope you enjoy the contests and win big prizes. NOW, LET THE CELEBRATION BEGIN!

Happy New Year, everyone! We hope you enjoyed the Cody contest in 2020, learned new MATLAB skills, and made a friend or two. While the 2020 contest has concluded, the fun and learning never end.

Please take the 1-minute survey to talk about your experience (only 2 required questions). Our goal is to make future contests better and more appealing to you, so your feedback is critical to us.

Thank you in advance and hope to see you again in the 2021 contest.

We are excited to announce that Cody Contest 2020 starts today! Again, the rule is simple - solve any problem and rate its difficulty. If you have any question, please visit our FAQs page first. Want to know your ranking? Check out the contest leaderboard .

Happy problem-solving! We hope you are a winner.

Below are some FAQs for the Cody contest 2020. If you have any additional questions, ask your questions by replying to this post. We will keep updating the FAQs.

Q1: If I rate a problem I solved before the contest, will I still get a raffle ticket?

A: Yes. You can rate any problem you have solved, whether it was before or during the contest period.

Q2: When will I receive the contest badges that I've earned?

A: All badges will be awarded after the contest ends.

Q3: How do I know if I’m the raffle winner?

A: If you are a winner, we will contact you to get your name and mailing address. You can find the list of winners on the Cody contest page .

Q4: When will I receive my T-shirt or hat?

A: You will typically receive your prize within a few weeks. It might take longer for international shipping.

Q5: I'm new to Cody. If I have some questions about using Cody, how can I get help?

A: You can ask your question by replying this post. Other community users might help you and we will also monitor the threads. You might also find answers here .

Q6: What do I do if I have a question about a specific problem?

A: If the problem description is unclear, the test suite is broken, or similar concerns arise, post your question(s) as a comment on the specific problem page. If you are having a hard time solving a problem, you can post a comment to your solution attempt (after submitting it). However, do not ask other people to solve problems for you.

Q7: If I find a bug or notice someone is cheating/spamming during the contest, how can I report it?

A: Use Web Site Feedback . Select "MATLAB Central" from the category list.

Q8: Why can't I rate a problem?

A: To rate a problem, you must solve that problem first and have at least 50 total points.

Rik
Rik
Last activity 2022-11-4

There are multiple ways to create a graphical user interface (GUI) in Matlab. Which method is the best depends on multiple factors: the complexity of the project, to what extent it should be a long-term solution, on what releases your GUI should work, your available time, your skill level, and probably other factors I'm forgetting.
To keep the thread clear I'll attempt to provide a short outline a few ways in this question, and leave the details for the answers. (@anyone with editing privileges: feel free to update the section below if I missed something important and am slow in editing this question)
---------------------------------------------------------------------------------------------------
GUIDE
GUIDE is probably the first tool new users will encounter. It is very useful for quickly putting something together, but it is otherwise fairly limited. It requires maintaining (and distributing) both a .m and a .fig file. Note that the GUIDE environment will be removed in a future release. After GUIDE is removed, existing GUIDE apps will continue to run in Matlab but they will not be editable in GUIDE. If you're starting a new GUI, don't use GUIDE. If you're updating an existing GUIDE GUI, migrate it to AppDesigner. In R2021a the first step for this removal was taken: all templates except the blank template have been removed.
GUILT
Although I haven't had a detailed look myself, it seems a list like this is not complete without at least mentioning the GUI Layout Toolbox, which is available on the file exchange and offers a lot of customization options.
Programmatic GUIs
You can bypass GUIDE and use the normal figures and functions like uicontrol to build GUIs from code. This makes the design less visual, but more flexible for future additions.
App Designer
The official successor to GUIDE, AppDesigner is not based on functions, but works similar to a class. It uses uifigure and mostly uses graphical elements that are incompatible with 'normal' GUIs that are created with a figure (or .fig).
Summary:
Dynamically accessing variable names can negatively impact the readability of your code and can cause it to run slower by preventing MATLAB from optimizing it as well as it could if you used alternate techniques. The most common alternative is to use simple and efficient indexing.
Explanation:
Sometimes beginners (and some self-taught professors) think it would be a good idea to dynamically create or access variable names, the variables are often named something like these:
  • matrix1, matrix2, matrix3, matrix4, ...
  • test_20kmh, test_50kmh, test_80kmh, ...
  • nameA, nameB, nameC, nameD,...
Good reasons why dynamic variable names should be avoided:
There are much better alternatives to accessing dynamic variable names:
Note that avoiding eval (and assignin, etc.) is not some esoteric MATLAB restriction, it also applies to many other programming languages as well:
MATLAB Documentation:
If you are not interested in reading the answers below then at least read MATLAB's own documentation on this topic Alternatives to the eval Function, which states "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended. The preferred method is to store related data in a single array." Data in a single array can be accessed very efficiently using indexing.
Note that all of these problems and disadvantages also apply to functions load (without an output variable), assignin, evalin, and evalc, and the MATLAB documentation explicitly recommends to "Avoid functions such as eval, evalc, evalin, and feval(fname)".
The official MATLAB blogs explain why eval should be avoided, the better alternatives to eval, and clearly recommend against magically creating variables. Using eval comes out at position number one on this list of Top 10 MATLAB Code Practices That Make Me Cry. Experienced MATLAB users recommend avoiding using eval for trivial code, and have written extensively on this topic.
The community is very helpful, yet I feel really powerless that I cannot find the appropriate way to code, nor find the problems with the codes I have written. I have read numerous books on MATLAB, mostly related with science and engineering applications. Any advice to improve would be greatly appreciated. Thanks.
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?
What is the best way to learn MATLAB at home without a tutor?