主要内容

Results for


Exciting news for students! 🚀Simulink Student Challenge 2023 is live! Unleash your engineering skills and compete for exciting rewards. Submission deadline is December 12th, 2023!
Over the weekend I came across a pi approximation using durations of years and weeks (image below, Wolfram, eq. 89), accurate to 6 digits using the average Gregorian year (365.2425 days).
Here it is in MATLAB. I divided by 1 week at the end rather than multiplying by its reciprocal because you can’t divide a numeric by a duration in MATLAB (1/week).
weeks = @(n)n*days(7);
piApprox = ((years(13)-weeks(6))/years(13) + weeks(3)) / weeks(1)
% piApprox = 3.141593493469302
Here’s a breakdown
  • The first argument becomes 12.885 yrs / 13 yrs or 0.99115
  • Add three weeks: 0.99115 + 3 weeks = 21.991 days
  • The reduced fraction becomes 21.991 days / 7 days
Now it looks a lot closer to the more familiar approximation for pi 22/7 but with greater precision!
This person used computer version to build a keyboard input, and used standard flag semaphore for the positions.
Flag semaphore is used mostly by sailors to be able to communicate optically over a distance; it does not need anything more than make-shift flags (but binoculars or telescopes can help.) Trained users can go faster than you might guess.
Chen, Rena, and I are at a community management event. It's great to be with others talking about relationships, trust, and co-creation.
Chen Lin
Chen Lin
Last activity 2023-10-16

I'm in a community conference in Boston today and see what snacks we get! The organizer said it's a coincidence, but it's definitly a good idea to have them in our MathWorks community meetings.
A research team found a way to trick a number of AI systems by injecting carefully placed nonsense -- for example being able able to beat DeepMind's Go game.
This video discusses the "Cody" bridge, which is a pedestrian bridge over a canal that has been designed to move up and out of the way when ships need to travel through. The mathematics of the bridge movement are discussed and diagrammed. It is unique and educational.
Recently developed: a "microscope" based on touch and stereo vision.
Using touch removes the possibility of optical confusion -- for example, black on touch is only due to shape, not due to the possibility that the object has a black patch.
Sorry, you might need a Facebook account to watch the video.
(Sorry - it should be 2023b by now.)
I'm curious how the community uses the hold command when creating charts and graphics in MATLAB. In short, hold on sets up the axes to add new objects to the axes while hold off sets up the axes to reset when new objects are added.
When you use hold on do you always follow up with hold off? What's your reasoning on this decision?
Can't wait to discuss this here! I'd love to hear from newbies and experts alike!
Calling all students! New to MATLAB or need helpful resources? Check out our MATLAB GitHub for Students repository! Find MATLAB examples, videos, cheat sheets, and more!
Visit the repository here: MATLAB GitHub for Students
The way we've solved ODEs in MATLAB has been relatively unchanged at the user-level for decades. Indeed, I consider ode45 to be as iconic as backslash! There have been a few new solvers in recent years -- ode78 and ode89 for example -- and various things have gotten much faster but if you learned how to solve ODEs in MATLAB in 1997 then your knowledge is still applicable today.
In R2023b, there's a completely new framework for solving ODEs and I love it! You might argue that I'm contractually obliged to love it since I'm a MathWorker but I can assure you this is the real thing!
The new interface makes a lot of things a much easier to do. Its also setting us up for a future where we'll be able to do some very cool algorithmic stuff behind the scenes.
Let me know what you think of the new functionality and what you think MathWorks should be doing next in the area of ODEs.
To solve the puzzle, first unscramble each of the words on the left. Then rearrange the letters in the yellow shaded boxes to complete the sentence on the right.
If you enjoyed this puzzle let me know with a like or in the comments below and I'll post more of them. Please don't post your answer, or any hints, and spoil it for those who come across this puzzle after you!! If you want to check your answer, you can messge me your guess through the link on my profile card (click on my name, Rena Berman, above and then on the envelope icon in the top right corner of the profile card that appears).
The MATLAB Answers community is an invaluable resource for all MATLAB users, providing selfless assistance and support. However, with the emergence of AI-based chatbots, like chatGPT, there may be concerns about the future relevance and utility of the MATLAB Answer community. What are your thoughts?
I've now seen linear programming questions pop up on Answers recently, with some common failure modes for linprog that people seem not to understand.
One basic failure mode is an infeasible problem. What does this mean, and can it be resolved?
The most common failure mode seems to be a unbounded problem. What does this mean? How can it be avoided/solved/fixed? Is there some direction I can move where the objective obviously grows without bounds towards +/- inf?
Finally, I also see questions where someone wants the tool to produce all possible solutions.
A truly good exposition about linear programming would probably result in a complete course on the subject, and Aswers is limited in how much I can write (plus I'll only have a finite amount of energy to keep writing.) I'll try to answer each sub-question as separate answers, but if someone else would like to offer their own take, feel free to do so as an answer, since it has been many years for me since I learned linear programming.
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)
Rik
Rik
Last activity 2024-9-17,13:25

Similar to what has happened with the wishlist threads (#1 #2 #3 #4 #5), the "what frustrates you about MATLAB" thread has become very large. This makes navigation difficult and increases page load times.
So here is the follow-up page.
What should you post where?
Wishlist threads (#1 #2 #3 #4 #5): bugs and feature requests for Matlab Answers
Frustation threads (#1 #2): frustations about usage and capabilities of Matlab itself
Missing feature threads (#1 #2): features that you whish Matlab would have had
Next Gen threads (#1): features that would break compatibility with previous versions, but would be nice to have
@anyone posting a new thread when the last one gets too large (about 50 answers seems a reasonable limit per thread), please update this list in all last threads. (if you don't have editing privileges, just post a comment asking someone to do the edit)