/matlabcentral/discussions/channelsChannels Discussions2024-04-23T11:02:33Ztag:ch.mathworks.com,2005:Topic/8482162024-03-05T14:47:09Z2024-04-17T00:33:02ZIntroducing ‘Discussions’: Your New Go-To Community Space for Best MATLAB Tips & Tricks and More<p>We are thrilled to announce the launch of a brand-new area within the MATLAB Central community – 'Discussions'. This exciting addition is designed to foster a stronger and more connected community.</p><p>Discover the 'Tips & Tricks' Channel
At the heart of 'Discussions' is the 'Tips & Tricks' channel. This is your ultimate destination for both sharing and discovering the best MATLAB tips.
Whether you're a seasoned MATLAB user with wisdom to share or a newcomer seeking advice, this channel is your platform. Here, you can post your own insights, ask for guidance on specific topics, and uncover hidden gems that can transform your MATLAB experience. It's more than just a channel; it's a community learning together; it’s your community blog!</p><p>More Than Just Tips
The 'Discussions' area offers much more. Explore the 'Ideas'channel to share and debate innovative product ideas. Dive into the 'Fun'channel to enjoy memes and light-hearted content with fellow MATLAB enthusiasts. Or wander into 'Off Topic'for intriguing discussions that might not be related to MATLAB.</p><p>Follow the channels!
We highly encourage every member of the MATLAB Central community to follow the channels you are interested in and participate in 'Discussions'. Together, we can achieve more, learn more, and connect more.</p>Chen Linhttps://ch.mathworks.com/matlabcentral/profile/authors/6682740tag:ch.mathworks.com,2005:Topic/8441012024-02-02T17:41:51Z2024-02-04T11:24:23ZRead this before posting<p>Hello and a warm welcome to all! We're thrilled to have you visit our community. MATLAB Central is a place for learning, sharing, and connecting with others who share your passion for MATLAB and Simulink. To ensure you have the best experience, here are some tips to get you started:
Read the Community Guidelines: Understanding our community standards is crucial. Please take a moment to familiarize yourself with them. Keep in mind that posts not adhering to these guidelines may be flagged by moderators or other community members.
Ask Technical Questions at MATLAB Answers: If you have questions related to MathWorks products, head over to MATLAB Answers (new question form - Ask the community). It's the go-to spot for technical inquiries, with responses often provided within an hour, depending on the complexity of the question and volunteer availability. To increase your chances of a speedy reply, check out our tips on how to craft a good question (link to post on asking good questions).
Choosing the Right Channel: We offer a variety of discussion channels tailored to different contexts. Select the one that best fits your post. If you're unsure, the General channel is always a safe bet. If you feel there's a need for a new channel, we encourage you to suggest it in the Ideas channel.
Reporting Issues: If you encounter posts that violate our guidelines, please use the 🚩Flag/Report feature (found in the 3-dot menu) to bring them to our attention.
Quality Control: We strive to maintain a high standard of discussion. Accounts that post spam or too much nonsense may be subject to moderation, which can include temporary suspensions or permanent bans.
Share Your Ideas: Your feedback is invaluable. If you have suggestions on how we can improve the community or MathWorks products, the Ideas channel is the perfect place to voice your thoughts.
Enjoy yourself and have fun! We're committed to fostering a supportive and educational environment. Dive into discussions, share your expertise, and grow your knowledge. We're excited to see what you'll contribute to the community!</p>Davidhttps://ch.mathworks.com/matlabcentral/profile/authors/4480925tag:ch.mathworks.com,2005:Topic/8314622023-11-07T18:43:52Z2023-11-09T13:55:07Z🚀 The MATLAB AI Chat Playground Has Launched<p>The MATLAB AI Chat Playground is open to everyone!
Check it out here on the community: https://www.mathworks.com/matlabcentral/playground</p><p>I just published a blog post announcing the release.</p>Hans Scharlerhttps://ch.mathworks.com/matlabcentral/profile/authors/5863695tag:ch.mathworks.com,2005:Topic/8567462024-04-22T11:36:15Z2024-04-23T11:02:33ZWhich of the following does not return the correct length (5) of v = [6,2,9,7,3]?goc3https://ch.mathworks.com/matlabcentral/profile/authors/5349647tag:ch.mathworks.com,2005:Topic/8566562024-04-22T05:54:28Z2024-04-22T20:17:19ZIs there a position for Matlab Community remote support work?<p>As far as I know, the MATLAB Community (including Matlab Central and Mathworks' official GitHub repository) has always been a vibrant and diverse professional and amateur community of MATLAB users from various fields globally. Being a part of it myself, especially in recent years, I have not only benefited continuously from the community but also tried to give back by helping other users in need.
I am a senior MATLAB user from Shenzhen, China, and I have a deep passion for MATLAB, applying it in various scenarios. Due to the less than ideal job market in my current social environment, I am hoping to find a position for remote support work within the Matlab Community. I wonder if this is realistic. For instance, Mathworks has been open-sourcing many repositories in recent years, especially in the field of deep learning with typical applications across industries. I am eager to use the latest MATLAB features to implement state-of-the-art algorithms. Additionally, I occasionally contribute through GitHub issues and pull requests.
In conclusion, I am looking forward to the opportunity to formally join the Matlab Community in a remote support role, dedicating more energy to giving back to the community and making the world a better place! (If a Mathworks employer can contact me, all the better~)</p>cui,xingxinghttps://ch.mathworks.com/matlabcentral/profile/authors/3388605tag:ch.mathworks.com,2005:Topic/8568112024-04-22T14:58:32Z2024-04-22T17:58:49ZDebugging Using Conditional Breakpoints & fprintf<p>Temporary print statements are often helpful during debugging but it's easy to forget to remove the statements or sometimes you may not have writing privileges for the file. This tip uses conditional breakpoints to add print statements without ever editing the file!
What are conditional breakpoints?
Conditional breakpoints allow you to write a conditional statement that is executed when the selected line is hit and if the condition returns true, MATLAB pauses at that line. Otherwise, it continues.
The Hack: use ~fprintf() as the condition
fprintf prints information to the command window and returns the size of the message in bytes. The message size will always be greater than 0 which will always evaluate as true when converted to logical. Therefore, by negating an fprintf statement within a conditional breakpoint, the fprintf command will execute, print to the command window, and evalute as false which means the execution will continue uninterupted!
How to set a conditional break point
1. Right click the line number where you want the condition to be evaluated and select "Set Conditional Breakpoint"</p><p>2. Enter a valid MATLAB expression that returns a logical scalar value in the editor dialog.</p><p>Handy one-liners
Check if a line is reached: Don't forget the negation (~) and the line break (\n)!
~fprintf('Entered callback function\n')
Display the call stack from the break point line: one of my favorites!
~fprintf('%s\n',formattedDisplayText(struct2table(dbstack)))
Inspect variable values: For scalar values,
~fprintf('v = %.5f\n', v)
Use formattedDisplayText to convert more complex data to a string
~fprintf('%s\n', formattedDisplayText(v)).
Make sense of frequent hits: In some situations such as responses to listeners or interactive callbacks, a line can be executed 100s of times per second. Incorporate a timestamp to differentiate messages during rapid execution.
~fprintf('WindowButtonDownFcn - %s\n', datetime('now'))
Closing
This tip not only keeps your code clean but also offers a dynamic way to monitor code execution and variable states without permanent modifications. Interested in digging deeper? @Steve Eddins takes this tip to the next level with his Code Trace for MATLAB tool available on the File Exchange (read more).</p><p>Summary animation</p><p>To reproduce the events in this animation:
% buttonDownFcnDemo.m
fig = figure();
tcl = tiledlayout(4,4,'TileSpacing','compact');
for i = 1:16
ax = nexttile(tcl);
title(ax,"#"+string(i))
ax.ButtonDownFcn = @axesButtonDownFcn;
xlim(ax,[-1 1])
ylim(ax,[-1,1])
hold(ax,'on')
end</p><p>function axesButtonDownFcn(obj,event)
colors = lines(16);
plot(obj,event.IntersectionPoint(1),event.IntersectionPoint(2),...
'ko','MarkerFaceColor',colors(obj.Layout.Tile,:))
end</p>Adam Danzhttps://ch.mathworks.com/matlabcentral/profile/authors/25613423tag:ch.mathworks.com,2005:Topic/8546812024-04-12T16:15:52Z2024-04-22T12:37:58ZPet Day with PetWorks photo contest <p>Mari is helping Dad work.</p>Vonny Groosehttps://ch.mathworks.com/matlabcentral/profile/authors/13140626tag:ch.mathworks.com,2005:Topic/8459982024-02-15T23:19:26Z2024-04-20T15:07:15ZTricks for Sphere Texturing<p>If you've dabbled in "procedural generation," (algorithmically generating natural features), you may have come across the problem of sphere texturing. How to seamlessly texture a sphere is not immediately obvious. Watch what happens, for example, if you try adding power law noise to an evenly sampled grid of spherical angle coordinates (i.e. a "UV sphere" in Blender-speak):
% Example: how [not] to texture a sphere:
rng(2, 'twister'); % Make what I have here repeatable for you</p><p>% Make our radial noise, mapped onto an equal spaced longitude and latitude
% grid.
N = 51;
b = linspace(-1, 1, N).^2;
r = abs(ifft2(exp(6i*rand(N))./(b'+b+1e-5))); % Power law noise
r = rescale(r, 0, 1) + 5;
[lon, lat] = meshgrid(linspace(0, 2*pi, N), linspace(-pi/2, pi/2, N));
[x2, y2, z2] = sph2cart(lon, lat, r);
r2d = @(x)x*180/pi;</p><p>% Radial surface texture
subplot(1, 3, 1);
imagesc(r, 'Xdata', r2d(lon(1,:)), 'Ydata', r2d(lat(:, 1)));
xlabel('Longitude (Deg)');
ylabel('Latitude (Deg)');
title('Texture (radial variation)');</p><p>% View from z axis
subplot(1, 3, 2);
surf(x2, y2, z2, r);
axis equal
view([0, 90]);
title('Top view');</p><p>% Side view
subplot(1, 3, 3);
surf(x2, y2, z2, r);
axis equal
view([-90, 0]);
title('Side view');</p><p>The created surface shows "pinching" at the poles due to different radial values mapping to the same location. Furthermore, the noise statistics change based on the density of the sampling on the surface.
How can this be avoided? One standard method is to create a textured volume and sample the volume at points on a sphere. Code for doing this is quite simple:
rng default % Make our noise realization repeatable</p><p>% Create our 3D power-law noise
N = 201;
b = linspace(-1, 1, N);
[x3, y3, z3] = meshgrid(b, b, b);
b3 = x3.^2 + y3.^2 + z3.^2;
r = abs(ifftn(ifftshift(exp(6i*randn(size(b3)))./(b3.^1.2 + 1e-6))));</p><p>% Modify it - make it more interesting
r = rescale(r);
r = r./(abs(r - 0.5) + .1);</p><p>% Sample on a sphere
[x, y, z] = sphere(500);</p><p>% Plot
ir = interp3(x3, y3, z3, r, x, y, z, 'linear', 0);
surf(x, y, z, ir);
shading flat
axis equal off
set(gcf, 'color', 'k');
colormap(gray);
The result of evaluating this code is a seamless, textured sphere with no discontinuities at the poles or variation in the spatial statistics of the noise texture:</p><p>But what if you want to smooth it or perform some other local texture modification? Smoothing the volume and resampling is not equivalent to smoothing the surficial features shown on the map above.
A more flexible alternative is to treat the samples on the sphere surface as a set of interconnected nodes that are influenced by adjacent values. Using this approach we can start by defining the set of nodes on a sphere surface. These can be sampled almost arbitrarily, though the noise statistics will vary depending on the sampling strategy.
One noise realisation I find attractive can be had by randomly sampling a sphere. Normalizing a point in N-dimensional space by its 2-norm projects it to the surface of an N-dimensional unit sphere, so randomly sampling a sphere can be done very easily using randn() and vecnorm():
N = 5e3; % Number of nodes on our sphere
g=randn(3,N); % Random 3D points around origin
p=g./vecnorm(g); % Projected to unit sphere
The next step is to find each point's "neighbors." The first step is to find the convex hull. Since each point is on the sphere, the convex hull will include each point as a vertex in the triangulation:
k=convhull(p');
In the above, k is an N x 3 set of indices where each row represents a unique triangle formed by a triplicate of points on the sphere surface. The vertices of the full set of triangles containing a point describe the list of neighbors to that point.
What we want now is a large, sparse symmetric matrix where the indices of the columns & rows represent the indices of the points on the sphere and the nth row (and/or column) contains non-zero entries at the indices corresponding to the neighbors of the nth point.
How to do this? You could set up a tiresome nested for-loop searching for all rows (triangles) in k that contain some index n, or you could directly index via:
c=@(x)sparse(k(:,x)*[1,1,1],k,1,N,N);
t=c(1)|c(2)|c(3);
The result is the desired sparse connectivity matrix: a matrix with non-zero entries defining neighboring points.
So how do we create a textured sphere with this connectivity matrix? We will use it to form a set of equations that, when combined with the concept of "regularization," will allow us to determine the properties of the randomness on the surface. Our regularizer will penalize the difference of the radial distance of a point and the average of its neighbors. To do this we replace the main diagonal with the negative of the sum of the off-diagonal components so that the rows and columns are zero-mean. This can be done via:
w=spdiags(-sum(t,2)+1,0,double(t));
Now we invoke a bit of linear algebra. Pretend x is an N-length vector representing the radial distance of each point on our sphere with the noise realization we desire. Y will be an N-length vector of "observations" we are going to generate randomly, in this case using a uniform distribution (because it has a bias and we want a non-zero average radius, but you can play around with different distributions than uniform to get different effects):
Y=rand(N,1);
and A is going to be our "transformation" matrix mapping x to our noisy observations:
Ax = Y
In this case both x and Y are N length vectors and A is just the identity matrix:
A = speye(N);
Y, however, doesn't create the noise realization we want. So in the equation above, when solving for x we are going to introduce a regularizer which is going to penalize unwanted behavior of x by some amount. That behavior is defined by the point-neighbor radial differences represented in matrix w. Our estimate of x can then be found using one of my favorite Matlab assets, the "\" operator:
smoothness = 10; % Smoothness penalty: higher is smoother
x = (A+smoothness*w'*w)\Y; % Solving for radii
The vector x now contains the radii with the specified noise realization for the sphere which can be created simply by multiplying x by p and plotting using trisurf:
p2 = p.*x';
trisurf(k,p2(1,:),p2(2,:),p2(3,:),'FaceC', 'w', 'EdgeC', 'none','AmbientS',0,'DiffuseS',0.6,'SpecularS',1);
light;
set(gca, 'color', 'k');
axis equal</p><p>The following images show what happens as you change the smoothness parameter using values [.1, 1, 10, 100] (left to right):</p><p>Now you know a couple ways to make a textured sphere: that's the starting point for having a lot of fun with basic procedural planet, moon, or astroid generation! Here's some examples of things you can create based on these general ideas:</p>Timhttps://ch.mathworks.com/matlabcentral/profile/authors/4596244tag:ch.mathworks.com,2005:Topic/8514962024-03-29T14:55:24Z2024-04-19T23:11:21ZStarter MATLAB Script<p>I am often talking to new MATLAB users. I have put together one script. If you know how this script works, why, and what each line means, you will be well on your way on your MATLAB learning journey.
% Clear existing variables and close figures
clear;
close all;</p><p>% Print to the Command Window
disp('Hello, welcome to MATLAB!');</p><p>% Create a simple vector and matrix
vector = [1, 2, 3, 4, 5];
matrix = [1, 2, 3; 4, 5, 6; 7, 8, 9];</p><p>% Display the created vector and matrix
disp('Created vector:');
disp(vector);
disp('Created matrix:');
disp(matrix);</p><p>% Perform element-wise multiplication
result = vector .* 2;</p><p>% Display the result of the operation
disp('Result of element-wise multiplication of the vector by 2:');
disp(result);</p><p>% Create plot
x = 0:0.1:2*pi; % Generate values from 0 to 2*pi
y = sin(x); % Calculate the sine of these values</p><p>% Plotting
figure; % Create a new figure window
plot(x, y); % Plot x vs. y
title('Simple Plot of sin(x)'); % Give the plot a title
xlabel('x'); % Label the x-axis
ylabel('sin(x)'); % Label the y-axis
grid on; % Turn on the grid</p><p>disp('This is the end of the script. Explore MATLAB further to learn more!');</p>Hans Scharlerhttps://ch.mathworks.com/matlabcentral/profile/authors/5863695tag:ch.mathworks.com,2005:Topic/8545762024-04-11T17:02:21Z2024-04-19T23:01:40Z#nationalpetday Tucker (a.k.a Tuckaroo) never ceases to amaze me<p>Today, he got dressed for work to design some new dog toy-making algorithms. #nationalpetday</p>Tom Sleeperhttps://ch.mathworks.com/matlabcentral/profile/authors/18981008tag:ch.mathworks.com,2005:Topic/8563562024-04-19T14:23:13Z2024-04-19T22:01:56ZIntroducing the User Following Feature on MATLAB Central<p>We're thrilled to unveil a new feature in the MATLAB Central community: User Following.
Our community is so lucky to have many experienced MATLAB experts who generously share their knowledge and insights across different applications, including Answers, File Exchange, Discussions, Contests, or Blogs.
With the introduction of User Following feature, you can now easily track new content across different areas and engage in discussions with people you follow. Simply click the ‘Follow’ button located on their profile page to start.</p><p>Depending on your communication setting, you will receive notifications via email and/or view updates in your ‘Followed Activity’ feeds. To tailor your feed, select the ‘People’ filter and focus on activities from those you follow.</p><p>We strongly encourage you to take advantage of the User Following feature to foster learning and collaboration within our vibrant community.
Who will be the first person you choose to follow? Share your answer in the comments section below and let's inspire each other to explore new horizons together.</p>Chen Linhttps://ch.mathworks.com/matlabcentral/profile/authors/6682740tag:ch.mathworks.com,2005:Topic/8560062024-04-18T00:37:01Z2024-04-18T14:13:57ZAI Models Are Improving Every Year<p>How long until the 'dumbest' models are smarter than your average person? Thanks for sharing this article @Adam Danz
https://sherwood.news/tech/how-do-ai-models-stack-up-vs-humans-on-standardized-benchmarks/</p>Davidhttps://ch.mathworks.com/matlabcentral/profile/authors/4480925tag:ch.mathworks.com,2005:Topic/8552662024-04-15T12:21:50Z2024-04-16T16:13:50ZWhich of the following is not really a missing value? (Or, which option is false?)goc3https://ch.mathworks.com/matlabcentral/profile/authors/5349647tag:ch.mathworks.com,2005:Topic/8555162024-04-16T11:49:16Z2024-04-16T11:49:16ZSeeking Contributors for Upcoming Book on Matrix Algebra with MATLAB for Undergraduate Students<p>Hello MathWorks Community,</p><p>I am excited to announce that I am currently working on a book project centered around Matrix Algebra, specifically designed for MATLAB users. This book aims to cater to undergraduate students in engineering, where Matrix Algebra serves as a foundational element.</p><p>Matrix Algebra is not only pivotal in understanding complex engineering concepts but also in applying these principles effectively in various technological solutions. MATLAB, renowned for its powerful computational capabilities, is an excellent tool to explore and implement these concepts, making it a perfect companion for this book.</p><p>As I embark on this journey to create a resource that bridges theoretical matrix algebra with practical MATLAB applications, I am looking for one or two knowledgeable individuals who have a firm grasp of both subjects. If you have experience in teaching or applying matrix algebra in engineering contexts and are familiar with MATLAB, your contribution could be invaluable.</p><p>Collaborators will help in shaping the content to ensure it is educational, engaging, and technically robust, making complex concepts accessible and applicable for students.</p><p>If you are interested in contributing to this project or know someone who might be, please reach out to discuss how we can work together to make this book a valuable resource for engineering students.</p><p>Thank you and looking forward to your participation!</p>Athanasios Paraskevopouloshttps://ch.mathworks.com/matlabcentral/profile/authors/30623616tag:ch.mathworks.com,2005:Topic/8551162024-04-14T16:05:38Z2024-04-14T16:05:38ZHow do mathematicians walk their dogs?<p>What's your way?</p>Athanasios Paraskevopouloshttps://ch.mathworks.com/matlabcentral/profile/authors/30623616tag:ch.mathworks.com,2005:Topic/8469732024-02-26T14:19:12Z2024-04-14T08:07:50ZWhich of the following will not produce a 3x3 array of zeros in MATLAB?goc3https://ch.mathworks.com/matlabcentral/profile/authors/5349647tag:ch.mathworks.com,2005:Topic/8534412024-04-05T16:53:08Z2024-04-12T18:28:33ZSpring is on the way!<p>What's the weather like in your place?</p>Chen Linhttps://ch.mathworks.com/matlabcentral/profile/authors/6682740tag:ch.mathworks.com,2005:Topic/8546862024-04-12T16:23:13Z2024-04-12T16:23:13ZEllipse Visualizer using MATLAB App Designer--Inspired by the Total Solar Eclipse 2024!<p>I created an ellipse visualizer in #MATLAB using App Designer! To read more about it, and how it ties to the recent total solar eclipse, check out my latest blog post:
https://www.davidyding.com/navPages/Ellipse</p><p>Github Repo of the app (you can open it on MATLAB Online!):
https://github.com/dvfire123/EllipseVisualizer/tree/main</p>David Dinghttps://ch.mathworks.com/matlabcentral/profile/authors/9117269tag:ch.mathworks.com,2005:Topic/8479762022-02-23T09:14:30Z2024-04-12T13:14:25ZTUTORIAL: Comma-Separated Lists and How to Use Them<p>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:
https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html
https://www.mathworks.com/help/matlab/matlab_prog/access-multiple-elements-of-a-nonscalar-struct-array.html
https://www.mathworks.com/company/newsletters/articles/matlab-tips-and-tricks-exploiting-the-comma-separated-list-vectorizing-cell-array-and-structure-references.html
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)</p>Stephen23https://ch.mathworks.com/matlabcentral/profile/authors/3102170tag:ch.mathworks.com,2005:Topic/8500512024-03-20T17:51:24Z2024-04-11T16:12:03ZR2024a - What are you looking forward to?<p>The latest release is pretty much upon us. Official annoucements will be coming soon and the eagle-eyed among you will have started to notice some things shifting around on the MathWorks website as we ready for this.
The pre-release has been available for a while. Maybe you've played with it? I have...I've even been quietly using it to write some of my latest blog posts...and I have several queued up for publication after MathWorks officially drops the release.
At the time of writing, this page points to the pre-release highlights. Prerelease Release Highlights - MATLAB & Simulink (mathworks.com)
What excites you about this release? why?</p>Mike Croucherhttps://ch.mathworks.com/matlabcentral/profile/authors/20789457