主要内容

Results for


Two fun community contests: MATLAB Mini Hack 2022 and Cody 10th Anniversary will start on Oct 3rd, 2022. Are you ready for the challenges and big prizes?
How to Play
1. MATLAB Mini Hack 2022 contest:
Use up to 280 characters of MATLAB code to generate an interesting image. New in 2022 contest: You'll be allowed to use functions from File Exchange entries and/or certain MathWorks toolboxes in different weeks.
2. Cody 10th Anniversary contest:
Solve at least 1 Cody problem per day during the 4-week contest period. We will reward participants with the longest streak of days of problem-solving!
Tips to Win
1. MATLAB Mini Hack 2022: Spend time creating your best work (either a new or remixed entry).
2. Cody 10th Anniversary: Make sure you start on the 1st day (Oct 3rd). This is the key if you want to win one of the grand prizes (worth marking your calendar?)
3. Act now: No matter if you want to join either the Mini Hack, Cody, or both. Start planning your strategy today.
Good luck! We hope you are the winner.
Introduction
Comma-separated lists are really very simple. You use them all the time. Here is one:
a,b,c,d
That is a comma-separated list containing four variables, the variables a, b, c, and d. Every time you write a list separated by commas then you are writing a comma-separated list. Most commonly you would write a comma-separated list as inputs when calling a function:
fun(a,b,c,d)
or as arguments to the concatenation operator or cell construction operator:
[a,b,c,d]
{a,b,c,d}
or as function outputs:
[a,b,c,d] = fun();
It is very important to understand that in general a comma-separated list is NOT one variable (but it could be). However, sometimes it is useful to create a comma-separated list from one variable (or define one variable from a comma-separated list), and MATLAB has several ways of doing this from various container array types:
1) from a field of a structure array using dot-indexing:
struct_array.field % all elements
struct_array(idx).field % selected elements
2) from a cell array using curly-braces:
cell_array{:} % all elements
cell_array{idx} % selected elements
3) from a string array using curly-braces:
string_array{:} % all elements
string_array{idx} % selected elements
Note that in all cases, the comma-separated list consists of the content of the container array, not subsets (or "slices") of the container array itself (use parentheses to "slice" any array). In other words, they will be equivalent to writing this comma-separated list of the container array content:
content1, content2, content3, .. , contentN
and will return as many content arrays as the original container array has elements (or that you select using indexing, in the requested order). A comma-separated list of one element is just one array, but in general there can be any number of separate arrays in the comma-separated list (zero, one, two, three, four, or more). Here is an example showing that a comma-separated list generated from the content of a cell array is the same as a comma-separated list written explicitly:
>> C = {1,0,Inf};
>> C{:}
ans =
1
ans =
0
ans =
Inf
>> 1,0,Inf
ans =
1
ans =
0
ans =
Inf
How to Use Comma-Separated Lists
Function Inputs: Remember that every time you call a function with multiple input arguments you are using a comma-separated list:
fun(a,b,c,d)
and this is exactly why they are useful: because you can specify the arguments for a function or operator without knowing anything about the arguments (even how many there are). Using the example cell array from above:
>> vertcat(C{:})
ans =
1
0
Inf
which, as we should know by now, is exactly equivalent to writing the same comma-separated list directly into the function call:
>> vertcat(1,0,Inf)
ans =
1
0
Inf
How can we use this? Commonly these are used to generate vectors of values from a structure or cell array, e.g. to concatenate the filenames which are in the output structure of dir:
S = dir(..);
F = {S.name}
which is simply equivalent to
F = {S(1).name, S(2).name, S(3).name, .. , S(end).name}
Or, consider a function with multiple optional input arguments:
opt = {'HeaderLines',2, 'Delimiter',',', 'CollectOutputs',true);
fid = fopen(..);
C = textscan(fid,'%f%f',opt{:});
fclose(fid);
Note how we can pass the optional arguments as a comma-separated list. Remember how a comma-separated list is equivalent to writing var1,var2,var3,..., then the above example is really just this:
C = textscan(fid,'%f%f', 'HeaderLines',2, 'Delimiter',',', 'CollectOutputs',true)
with the added advantage that we can specify all of the optional arguments elsewhere and handle them as one cell array (e.g. as a function input, or at the top of the file). Or we could select which options we want simply by using indexing on that cell array. Note that varargin and varargout can also be useful here.
Function Outputs: In much the same way that the input arguments can be specified, so can an arbitrary number of output arguments. This is commonly used for functions which return a variable number of output arguments, specifically ind2sub and gradient and ndgrid. For example we can easily get all outputs of ndgrid, for any number of inputs (in this example three inputs and three outputs, determined by the number of elements in the cell array):
C = {1:3,4:7,8:9};
[C{:}] = ndgrid(C{:});
which is thus equivalent to:
[C{1},C{2},C{3}] = ndgrid(C{1},C{2},C{3});
Further Topics:
MATLAB documentation:
Click on these links to jump to relevant comments below:
Dynamic Indexing (indexing into arrays with arbitrary numbers of dimensions)
Nested Structures (why you get an error trying to index into a comma-separated list)
Summary
Just remember that in general a comma-separated list is not one variable (although they can be), and that they are exactly what they say: a list (of arrays) separated with commas. You use them all the time without even realizing it, every time you write this:
fun(a,b,c,d)

In the past 2 months, we had a lot of fun together playing in the two contests. To make future contests better and more appealing to you, we created a 1-minute survey to understand your experience.

Your feedback is critical to us. Thank you in advance and hope to see you in 2022!

After 7 weeks of fun, the MATLAB Central community 20th anniversary contests have concluded! Together, we shared the art of MATLAB and contributed to the battle against the global pandemic. See the fantastic stats below.

MATLAB Mini Hack Winners - Week 4

In Week 4, we invited the MATLAB Graphics team to help judge the entries. As the authors of the MATLAB functions used in every entry, they made sure every entry selected used a unique graphics function or technique from the other winners. Here are their choices:

1. Umbrellas by Shanshan Wang

Comment: Cool use of 'swarmchart' to make art from distributions; Only use of one of our newest graphics functions

2. Happy Sheep by Victoria

Comment: Cute!

3. Alien Giant by Jenny Bosten

Comment: Original idea, well textured, and efficient code

4. 3D Ultrasound by Adam Danz

Comment: Replicate source material very well. Effective use of lighting and material. Overall, impressive to produce this image given the limitation

5. Sunset in the Savanna by Sebastian Kraemer

Comment: Looks cool! Nice mix of 'image', 'fill' and 'scatter' commands.

6. Night Flight by Ratul Das

Comment: original; clever use of 'rectangle'

7. Lantern #2 by Tim

Comment: Nice use of 'getframe' to create a texture for 'surf' for a compelling picture

8. Geometric Design (6) by Daniel Pereira

Comment: Looks like some walls at MathWorks

9. Rosette 1313 by Alex P

Comment: Looks cool! Nice use of 'pcolor'

10. Mandelbrot contour by Sumihiro

Comment: Best use of contour!

11. Aim High by Murty PLN

Comment: Largest number of unique graphics objects for the Mini Hack (plot, patch,stairs,stem,text)

In the spirit of Mini Hack, the MATLAB Graphics team also created several cool graphs about the contest. Facing a similar space limit, I have picked only 2.

Bonus Prize Winners - Week 4

Congratulations to our 5 winners for their dual participation in the Treasure Hunt and the MATLAB Mini Hack. Yogiraj Bhagavatula, Pramod Devireddy, Devika U, FruitsLord, and Augusto Mazzei.

Lucky voters - Week 4

Congratulations to the lucky voters who cast the 12000th vote (Gordg Garin), 12500th vote (Eder Esteban Reyes), 13000th vote (Peram Balakrishna), 13500th vote (Emerson Nithiyaraj), 14000th vote(Sekar Naai), 14500th vote (Arika Amasarao), 15000th vote (Nikita Yakovlev), 15500th vote (Kesava Rao), and 16000th vote (Kundi Chandra Sekhar).

Grant Prize Winners

Finally, after validating entries and votes, we have picked the grand prize winners. We appreciate the time and effort you spent and the awesome entries you created. Huge congratulations!

1. Top 10 Authors of most voted entries

Each author will receive 5 customized T-shirts with the winning image and your name on the back of the T-shirts. You can choose the sizes and share them with your family or friends.

2. Top 10 Authors with most total votes

Top 10 contestants on the leaderboard will each get an Amazon gift card. The top 3 winners on the leaderboard will also earn special virtual badges.

  • Ciro Bermudez
  • KSSV
  • Juan Villacrés
  • Murty PLN
  • Pink_panther
  • Jenny Bosten
  • KARUPPASAMYPANDIYAN M
  • Jr
  • Adam Danz
  • Victoria

On behalf of the MATLAB Central community team, we thank you for joining our celebration of the MATLAB Central community’s 20th anniversary with us in the past 7 weeks. We hope you enjoyed these contests and look forward to seeing you in next year’s contests. Question: “What contests would you like to see next?”

In Week 3, we passed several amazing milestones! 1,000 Participants in the Treasure Hunt , 1,000 ENTRIES and 10,000 votes in the MATLAB Mini Hack , and $10,000 charity donation from both contests! I recommend you read Ned Gulley’s recent blog post , which is a fantastic summary of the contest highlights.

During the last week of this contest, we strongly encourage you to inspire your colleagues, classmates, or friends to participate by either VOTING or CREATING entries. To add some fun, we will give out a T-shirt to LUCKY voters who cast:

  • The 12000th vote
  • The 12500th vote
  • The 13000th vote
  • The 13500th vote
  • The 14000th vote
  • The 14500th vote
  • The 15000th vote
  • The 15500th vote
  • The 16000th vote

MATLAB Mini Hack Winners - Week 3

We’ve received many creative entries for our new categories. Congratulations to the winners! Each of you won a special edition T-shirt:

Greg, entry: better Christmas tree , category: Holidays

Ratul Das, entry: To All Pepperoni Lovers , category: Food

Peter Stampfli, entry: Louis V , category: Fractals

Adrien Leygue, entry: Stained Glass membrane , category: MathWorks Logo

Spencer Miesner, entry: ~Breathe~ , category: Album Cover

Stewart Thomas, entry: The only QR code you ever need , category: Black & White

Sebastian Kraemer, entry: sun , category: 3D

Jenny Bosten, entry: The joys of spring , category: Plant

Adam Danz, entry: MATropolis rooftop view , category: Illustration

Eric Ogier, entry: UFO , category: Fun

Simon Thor, entry: Mandelbrot in 52 characters , category: Concise

Tim, entry: Low Tide , category: Realism

Bonus Prize Winners - Week 3

We are giving out additional giveaways to participants of both the Treasure Hunt and the MATLAB Mini Hack . Congratulations to our 5 winners. Each of you has also won a special edition T-shirt.

  • Teodo
  • Dyuman Joshi
  • Shanshan Wang
  • Nirvik Sinha
  • Felipe Torres

Week 4

After the contest ends, we need additional time to validate entries for Grand Prize and Weekly Prize. The winners are expected to be announced within a couple of days after the contest ends. Thank you in advance for your patience.

In Week 2, the contest entered a new phase – the voting started! As of today, 6000+ votes have been cast on almost 1000 entries in the GALLERY! As a result, YOU raised $5000+ for Direct Relief in addition to the $2400 raised via the Treasure Hunt contest! We encourage you to continue sharing the contest to inspire others to participate by either voting or creating new entries so we can donate even more!

MATLAB Mini Hack Winners - Week 2

I won’t say judging is getting easier in Week 2 - amazing entries keep coming in every day. Congratulations to the winners! Each of you has won a special edition T-shirt.

Bonus Prize Winners - Week 2

We are giving out additional giveaways to participants of both the Treasure Hunt and the MATLAB Mini Hack . Congratulations to our 5 winners. Each of you has also won a special edition T-shirt.

  • Simon Thor
  • Eric Ogier
  • David Hill
  • Lyes Demri
  • Highphi

What’s new in Week 3?

In Week 3, we will add several new categories in which we hope to see more creative entries:

  • Holidays
  • Album covers
  • Food & Drinks
  • MathWorks logo
  • Fractals

In just one week, 500+ amazing entries were created. Math rocks and you rock!

Help us show the world the beauty of mathematics by sharing your work with your friends, classmates, or colleagues. You can also help fight the global pandemic by voting. For each vote, MathWorks will donate $1 to Direct Relief. See the Voting FAQs below for details.

MATLAB Mini Hack Winners - Week 1

Let’s start by saying: your awesome work made our judging VERY HARD! We came up with several categories with one winner each. Congratulations to the winners! Each of you won a special edition T-shirt:

Bonus Prize Winners - Week 1

As we announced last week, we are giving additional giveaways to participants of both the Treasure Hunt contest and the MATLAB Mini Hack contest . Congratulations to our 5 winners. Each of you also won a special edition T-shirt

  • Jan Orwat
  • warnerchang
  • Davide OLIVIERI
  • Daniel Niblett
  • KARUPPASAMYPANDIYAN M

Voting FAQs:

Q1: Who can vote?

Anyone with a MathWorks account can vote.

Q2: How many times can I vote?

There here is no limit to the number of votes you can cast. Vote for as many entries as you like (one vote per entry).

Q3: How do my votes increase MathWorks’ charity donation?

For every vote an entry gets, we will donate $1 to Direct Relief with a maximum amount of $20 donated per entry. MathWorks will donate up to a maximum of $20,000 based on the combined totals raised by task participation in the Treasure Hunt and voting in the MATLAB Mini Hack .

Q4. How do I win?

At the end of the contest, the top 10 participants on the leaderboard will each get an Amazon gift card and the top 3 will earn special badges. The 10 highest voted entries will win 5 customized T-shirts. See the full contest details.

Every week, we will also award surprise prizes for more fun.

Note that MathWorks staff are NOT eligible for prizes.

Q5: How do votes on my entries determine my rank on the leaderboard?

The total number of votes on ALL of your entries determines your rank on the leaderboard.

Q6: Do votes on remixed entries add votes to the original entry?

No. We count only direct votes on an entry.

Q7: Is the code (also) automatically compared to earlier submissions to determine the remix tree?

No. You have to remix an entry.

Just in 2 days since the contest started, we already have 200+ awesome entries in the MATLAB Mini Hack contests. We are excited to see so many talented and creative community members enjoying the contest and learning from each other.

If you haven’t created your entry, try remixing an entry you like. Make some SMALL changes and see what it would look like. Remix is highly encouraged in this contest.

If you haven’t entered the Treasure Hunt contest, give it a try. Your participation will not only win you a prize but also bump up MathWorks’ donation to a charity organization that fights the global pandemic.

Reminder:

  • Voting will start next Monday.
  • Weekly surprise giveaways will also be announced next Monday. Still time left to create your entries, original or remixed!

As part of MATLAB Central’s 20 year anniversary celebration, we created the MATLAB Mini Hack . The contest starts today on Oct. 4th!

What to do?

Generate an interesting image using up to 280 characters of MATLAB code.

Who can play?

Participants across all skill levels are welcome. Create original entries of your own code, remix others’ entries and make them your own, or simply vote on ENTRIES you love!

How to win prizes?

Those at the top of the leaderboard at the end of the contest will win up to $300 Amazon gift cards, 5 customized T-shirts, or special badges. Visit the prizes section on the contest page for more information.

To add more fun, we will award RANDOM PRIZES that every participant has a chance to win.

  • Each week, we will pick 5 players who participate in both the Treasure Hunt and MATLAB Mini Hack .
  • Each week, we will have different surprise giveaways.

Important Notes

  • The first week (Oct. 4th, 2021 ~ Oct. 10th 2021) is for creating entries only. Voting starts on Week 2.
  • Make sure you follow the contests (click the ‘follow the contests’ button on the top) to get notified when prizes are awarded and of other important announcements. We hope you are the winner!

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.
Inspired by Chad Greene's " MATLAB jokes or puns " thread, and in celebration of 15 years of the MathWorks Community site, does anyone out there want to share their poetic creativity? Limericks, haiku, sonnets... Go!
And to start off, my (slightly off-topic) submission on Chad's thread:
There was an old math guy called Cleve
who, while teaching, a pipe-dream conceived:
of a language so clean
you can say what you mean!
From our suffering we've all been relieved.
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.
Chad Greene
Chad Greene
Last activity 2023-9-12

Are there any good Matlab jokes? I don't mean why or any other Easter eggs, I mean good jokes involving Matlab. Actually, that bar may be a bit too high. Any jokes, good or bad, let's hear 'em.
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!