/matlabcentral/discussions/channelsChannels Discussions2024-02-21T09:57:57Ztag:www.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://www.mathworks.com/matlabcentral/profile/authors/4480925tag:www.mathworks.com,2005:Topic/8375142023-12-04T19:29:04Z2024-02-21T09:57:57ZNew Community Feature: AI Chat Playground<p>The MATLAB AI Chat Playground is now open to the whole community! Answer questions, write first draft MATLAB code, and generate examples of common functions with natural language.
The playground features a chat panel next to a lightweight MATLAB code editor. Use the chat panel to enter natural language prompts to return explanations and code. You can keep chatting with the AI to refine the results or make changes to the output.</p><p>Give it a try, provide feedback on the output, and check back often as we make improvements to the model and overall experience.</p>Hans Scharlerhttps://www.mathworks.com/matlabcentral/profile/authors/5863695tag:www.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://www.mathworks.com/matlabcentral/profile/authors/5863695tag:www.mathworks.com,2005:Topic/8460832024-02-17T08:38:13Z2024-02-20T16:19:41Zํ๋ ฌ์์ ๋ฉด์ ์ด๋ค? Determinant is area?<p>2 x 2 ํ๋ ฌ์ ํ๋ ฌ์์
ํ๋ ฌ์ ๋ row ๋ฒกํฐ๋ก ์ ์๋๋ ํํ์ฌ๋ณํ์ ๋ฉด์ ์ ๋๋ค.
๋ฌผ๋ก ๋ column ๋ฒกํฐ๋ก ์ ์๋๋ ํํ์ฌ๋ณํ์ ๋ฉด์ ์ด๊ธฐ๋ ํฉ๋๋ค.
์ข ๋ ์ ํํ๋ signed area์ ๋๋ค. ๋ฉด์ ์ด ์์๊ฐ ๋ ์๋ ์๋ค๋ ๋ป์ด์ฃ .
ํ๋ ฌ์ ๋ ํ(๋๋ ๋ ์ด)์ ๋ง๋ฐ๊พธ๋ฉด ํ๋ ฌ์์ ๋ถํธ๋ ๋ฐ๋๊ณ ๋ฉด์ ์ ๋ถํธ๋ ๋ฐ๋์ด์ผํฉ๋๋ค.</p><p>์ผ๋ฐ์ ์ผ๋ก n x n ํ๋ ฌ์ ํ๋ ฌ์์
๊ฐ row ๋ฒกํฐ(๋๋ ๊ฐ column ๋ฒกํฐ)๋ก ์ ์๋๋ N์ฐจ์ ๊ณต๊ฐ์ ํํ๋ฉด์ฒด(?)์ signed area์ ๋๋ค.
์ ๋๋ก ์ดํดํ๋ ค๋ฉด ๋์ํ์ ๊ฐ๋ ์ ๋ง์ด ๊ฐ์ง๊ณ ์์ผ ํ๋๋ฐ ์์ธํ ์ค๋ช ์ ์๋ตํฉ๋๋ค.(=์ ๋ ๋ชจ๋ฅธ๋ค๋ ๋ป)
๋ ์์ธํ ์๊ณ ์ถ์ผ์๋ฉด ์ํํ๋ ๋งํ์ '๋์ด ์ด์ผ๊ธฐ' ํธ์ ์ถ์ฒํฉ๋๋ค.
์ํ์ ์ธ ์ ์๋ฅผ ์๊ณ ์ถ์ผ์๋ฉด ์ํคํผ๋์๋ฅผ ๋ณด์๋ฉด ๋ฉ๋๋ค.</p><p>์ด๋ ๊ฒ ์๊ฒผ์ต๋๋ค. ์ข ๋ฌด์ญ์ต๋๋ค.</p><p>์๋ ์ฝ๋๋...
2 x 2 ํ๋ ฌ์ ๋ํด์ ์ด๊ฒ์ ์์ ์์ด ๊ทธ๋ฆผ๋ง์ผ๋ก ์ฆ๋ช ํ๋ ๊ณผ์ ์ ๋๋ค.
gif ์์ฑ์๋ ScreenToGif๋ฅผ ์ฌ์ฉํ์ต๋๋ค. (gif ๋ง๋ค๊ธฐ์ ์ด๊ฒ ํน์์งฑ์ธ๋ฏ)</p><p>Determinant of 2 x 2 matrix is...
An area of a parallelogram defined by two row vectors.
Of course, same one defined by two column vectors.
Precisely, a signed area, which means area can be negative.
If two rows (or columns) are swapped, both the sign of determinant and area change.</p><p>More generally, determinant of n x n matrix is...
Signed area of parallelepiped defined by rows (or columns) of the matrix in n-dim space.
For a full understanding, a lot of concepts from abstract algebra should be brought, which I will not write here. (Cuz I don't know them.)
For a mathematical definition of determinant, visit wikipedia.</p><p>A little scary, isn't it?</p><p>The code below is...
A process to prove the equality of the determinant of 2 x 2 matrix and the area of parallelogram.
ScreenToGif is used to generate gif animation (which is, to me, the easiest way to make gif).</p><p>% ๋ ์ (a, b), (c, d)์ ์ขํ
a = 4;
b = 1;
c = 1;
d = 3;</p><p>% patch ์ pre-define
lightgreen = [144, 238, 144]/255;
lightblue = [169, 190, 228]/255;
lightorange = [247, 195, 160]/255;</p><p>% animation params.
anim_Nsteps = 30;</p><p>% create window
figure('WindowStyle','docked')
ax = axes;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
ax.XTick = [];
ax.YTick = [];</p><p>hold on
ax.XLim = [-.4, a+c+1];
ax.YLim = [-.4, b+d+1];</p><p>% create ad-bc patch
area = patch([0, a, a+c, c], [0, b, b+d, d], lightgreen);
p_ab = plot(a, b, 'ko', 'MarkerFaceColor', 'k');
p_cd = plot(c, d, 'ko', 'MarkerFaceColor', 'k');
p_ab.UserData = text(a+0.1, b, '(a, b)', 'FontSize',16);
p_cd.UserData = text(c+0.1, d-0.2, '(c, d)', 'FontSize',16);
area.UserData = text((a+c)/2-0.5, (b+d)/2, 'ad-bc', 'FontSize', 18);</p><p>pause</p><p>%% Is this really ad-bc?</p><p>area.UserData.String = 'ad-bc...?';</p><p>pause</p><p>%% fade out ad-bc</p><p>fadeinout(area, 0)
area.UserData.Visible = 'off';</p><p>pause</p><p>%% fade in ad block</p><p>rect_ad = patch([0, a, a, 0], [0, 0, d, d], lightblue, 'EdgeAlpha', 0, 'FaceAlpha', 0);
uistack(rect_ad, 'bottom');</p><p>fadeinout(rect_ad, 1, t_pause=0.003)
draw_gridline(rect_ad, ["23", "34"])
rect_ad.UserData = text(mean(rect_ad.XData), mean(rect_ad.YData), 'ad', 'FontSize', 20, 'HorizontalAlignment', 'center');</p><p>pause</p><p>%% fade-in bc block</p><p>rect_bc = patch([0, c, c, 0], [0, 0, b, b], lightorange, 'EdgeAlpha', 0, 'FaceAlpha', 0);</p><p>fadeinout(rect_bc, 1, t_pause=0.0035)
draw_gridline(rect_bc, ["23", "34"])
rect_bc.UserData = text(b/2, c/2, 'bc', 'FontSize', 20, 'HorizontalAlignment', 'center');</p><p>pause</p><p>%% slide ad block</p><p>patch_slide(rect_ad, ...
[0, 0, 0, 0], [0, b, b, 0], t_pause=0.004)</p><p>draw_gridline(rect_ad, ["12", "34"])</p><p>pause</p><p>%% slide ad block</p><p>patch_slide(rect_ad, ...
[0, 0, d/(d/c-b/a), d/(d/c-b/a)],...
[0, 0, b/a*d/(d/c-b/a), b/a*d/(d/c-b/a)], t_pause=0.004)</p><p>draw_gridline(rect_ad, ["14", "23"])</p><p>pause</p><p>%% slide bc block</p><p>uistack(p_cd, 'top')
patch_slide(rect_bc, ...
[0, 0, 0, 0], [d, d, d, d], t_pause=0.004)</p><p>draw_gridline(rect_bc, "34")
pause</p><p>%% slide bc block</p><p>patch_slide(rect_bc, ...
[0, 0, a, a], [0, 0, 0, 0], t_pause=0.004)</p><p>draw_gridline(rect_bc, "23")</p><p>pause</p><p>%% slide bc block</p><p>patch_slide(rect_bc, ...
[d/(d/c-b/a), 0, 0, d/(d/c-b/a)], ...
[b/a*d/(d/c-b/a), 0, 0, b/a*d/(d/c-b/a)], t_pause=0.004)</p><p>pause</p><p>%% finalize: fade out ad, bc, and fade in ad-bc</p><p>rect_ad.UserData.Visible = 'off';
rect_bc.UserData.Visible = 'off';</p><p>fadeinout([rect_ad, rect_bc, area], [0, 0, 1])</p><p>area.UserData.String = 'ad-bc';
area.UserData.Visible = 'on';</p><p>%% functions</p><p>function fadeinout(objs, inout, options)
arguments
objs
inout % 1์ด๋ฉด fade-in, 0์ด๋ฉด fade-out
options.anim_Nsteps = 30
options.t_pause = 0.003
end</p><p>for alpha = linspace(0, 1, options.anim_Nsteps)
for i = 1:length(objs)
switch objs(i).Type
case 'patch'
objs(i).FaceAlpha = (inout(i)==1)*alpha + (inout(i)==0)*(1-alpha);
objs(i).EdgeAlpha = (inout(i)==1)*alpha + (inout(i)==0)*(1-alpha);
case 'constantline'
objs(i).Alpha = (inout(i)==1)*alpha + (inout(i)==0)*(1-alpha);
end
pause(options.t_pause)
end
end</p><p>end</p><p>function patch_slide(obj, x_dist, y_dist, options)
arguments
obj
x_dist
y_dist
options.anim_Nsteps = 30
options.t_pause = 0.003
end</p><p>dx = x_dist/options.anim_Nsteps;
dy = y_dist/options.anim_Nsteps;
for i=1:options.anim_Nsteps
obj.XData = obj.XData + dx(:);
obj.YData = obj.YData + dy(:);
obj.UserData.Position(1) = mean(obj.XData);
obj.UserData.Position(2) = mean(obj.YData);
pause(options.t_pause)
end</p><p>end</p><p>function draw_gridline(patch, where)</p><p>ax = patch.Parent;
for i=1:length(where)
v1 = str2double(where{i}(1));
v2 = str2double(where{i}(2));
x1 = patch.XData(v1);
x2 = patch.XData(v2);
y1 = patch.YData(v1);
y2 = patch.YData(v2);
if x1==x2
xline(x1, 'k--')
else
fplot(@(x) (y2-y1)/(x2-x1)*(x-x1)+y1, [ax.XLim(1), ax.XLim(2)], 'k--')
end
end</p><p>end</p>lazymatlabhttps://www.mathworks.com/matlabcentral/profile/authors/12626206tag:www.mathworks.com,2005:Topic/8460482024-02-16T12:47:36Z2024-02-16T14:30:14ZRender landscapes<p>I think that MATLAB's Flipbook Mini Hack had quite some inspiring entries. My work largely deals with digital elevation models (DEMs). Hence I really liked the random renderings of landscapes, in particular this one written by Tim which inspired me to adopt the code and apply to the example data that comes with my software TopoToolbox. The results and code are shown here.</p>Wolfgang Schwangharthttps://www.mathworks.com/matlabcentral/profile/authors/870595tag:www.mathworks.com,2005:Topic/8460382024-02-16T12:07:48Z2024-02-16T16:57:52ZProducing animated gifs from MATLAB Flipbook Mini Hack entries<p>On Valentine's day, the MathWorks linkedIn channel posted this animated gif</p><p>and immeditaely everyone wanted the code! It turns out that this is the result of my remix of @Zhaoxu Liu / slandarer's entry on the MATLAB Flipbook Mini Hack.
I pointed people to the Flipbook entry but, of course, that just gave the code to render a single frame and people wanted the full code to render the animated gif. That way, they could make personalised versions
I just published a blog post that gives the code used by the team behind the Mini Hack to produce the animated .gifs https://blogs.mathworks.com/matlab/2024/02/16/producing-animated-gifs-from-matlab-flipbook-mini-hack-entries/
Thanks again to @Zhaoxu Liu / slandarer for a great entry that seems like it will live for a long time :)</p>Mike Croucherhttps://www.mathworks.com/matlabcentral/profile/authors/20789457tag:www.mathworks.com,2005:Topic/8459982024-02-15T23:19:26Z2024-02-20T15:57:52ZTricks 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://www.mathworks.com/matlabcentral/profile/authors/4596244tag:www.mathworks.com,2005:Topic/8459932024-02-15T22:46:25Z2024-02-20T15:54:48ZCreate hyperlinks in the command window<p>The MATLAB command window isn't just for commands and outputsโit can also host interactive hyperlinks. These can serve as powerful shortcuts, enhancing the feedback you provide during code execution. Here are some hyperlinks I frequently use in fprintf statements, warnings, or error messages.
1. Open a website.
msg = "Could not download data from website.";
url = "https://blogs.mathworks.com/graphics-and-apps/";
hypertext = "Go to website"</p><p>fprintf(1,'%s <a href = "https://www.mathworks.com">href="matlab: web(''%s'') "</a>%s</a>\n',msg,url,hypertext);
Could not download data from website. Go to website</p><p>2. Open a folder in file explorer (Windows)
msg = "File saved to current directory.";
directory = cd();
hypertext = "[Open directory]";</p><p>fprintf(1,'%s <a href = "https://www.mathworks.com">href="matlab: winopen(''%s'') "</a>%s</a>\n',msg,directory,hypertext)
File saved to current directory. [Open directory]</p><p>3. Open a document (Windows)
msg = "Created database.csv.";
filepath = fullfile(cd,'database.csv');
hypertext = "[Open file]";</p><p>fprintf(1,'%s <a href = "https://www.mathworks.com">href="matlab: winopen(''%s'') "</a>%s</a>\n',msg,filepath,hypertext)
Created database.csv. [Open file]</p><p>4. Open an m-file and go to a specific line
msg = 'Go to';
file = 'streamline.m';
line = 51;
fprintf(1,'%s <a href = "https://www.mathworks.com">href="matlab: matlab.desktop.editor.openAndGoToLine(which(''%s''), %d); "</a>%s line %d</a>', msg, file, line, file, line);
Go to streamline.m line 51</p><p>5. Display more text
msg = 'Incomplete data detected.';
extendedInfo = '\tFilename: m32c4r28\n\tDate: 12/20/2014\n\tElectrode: (3,7)\n\tDepth: ???\n';
hypertext = '[Click for more info]';</p><p>warning('%s <a href = "https://www.mathworks.com">href="matlab: fprintf(''%s'') "</a>%s</a>', msg,extendedInfo,hypertext);
Warning: Incomplete data detected. [Click for more info] <a href = "https://www.mathworks.com">click</a>
Filename: m32c4r28
Date: 12/20/2014
Electrode: (3,7)
Depth: ???
6. Run a function
See Create Hyperlinks that Run Functions</p><p>Similarly, you can also add hyperlinks in figures and apps
uihyperlink (R2021a)
Create a hyperlink using text()</p>Adam Danzhttps://www.mathworks.com/matlabcentral/profile/authors/25613423tag:www.mathworks.com,2005:Topic/8458032024-02-14T15:39:27Z2024-02-14T16:00:51ZHappy Valentine's Day<p>See code here in our community contest area.
And what do you do for Valentine's Day?</p>Chen Linhttps://www.mathworks.com/matlabcentral/profile/authors/6682740tag:www.mathworks.com,2005:Topic/8453762024-02-10T13:59:09Z2024-02-10T19:23:19Zcontact technical support<p>which technical support should I contact/ask for the published Simscape example?</p>Khttps://www.mathworks.com/matlabcentral/profile/authors/9046909tag:www.mathworks.com,2005:Topic/8452762024-02-10T03:46:16Z2024-02-10T03:46:16ZFun Spring Festival Couplets<p>Happy year of the dragon.</p><img src = "/matlabcentral/discussions/uploaded_files/25976/data">Chen Linhttps://www.mathworks.com/matlabcentral/profile/authors/6682740tag:www.mathworks.com,2005:Topic/8452712024-02-10T02:15:38Z2024-02-10T02:15:38ZTrick to enlarge a matrix by padding it with zeros.<p>To enlarge an array with more rows and/or columns, you can set the lower right index to zero. This will pad the matrix with zeros.
m = rand(2, 3) % Initial matrix is 2 rows by 3 columns
mCopy = m;
% Now make it 2 rows by 5 columns
m(2, 5) = 0</p><p>m = mCopy; % Go back to original matrix.
% Now make it 3 rows by 3 columns
m(3, 3) = 0</p><p>m = mCopy; % Go back to original matrix.
% Now make it 3 rows by 7 columns
m(3, 7) = 0</p>Image Analysthttps://www.mathworks.com/matlabcentral/profile/authors/1343420tag:www.mathworks.com,2005:Topic/8451112024-02-08T18:24:33Z2024-02-08T18:24:33ZPrize Wheel?<p>I was looking into the possibility of making a spin-to-win prize wheel in MATLAB. I was looking around, and if someone has made one before they haven't shared. A labeled colored spinning wheel, that would slow down and stop (or I would take just stopping) at a random spot each time. I would love any tips or links to helpful resources!</p>Hannahhttps://www.mathworks.com/matlabcentral/profile/authors/30846629tag:www.mathworks.com,2005:Topic/8450362024-02-07T22:13:21Z2024-02-07T22:13:21Z[MATLAB Example] Increase Image Resolution using Deep Learning<p>Many of the examples in the MATLAB documentation are extremely high quality articles, often worthy of attention in their own right. Time to start celebrating them! Today's is how to increase Image Resolution using deep learning
https://uk.mathworks.com/help/deeplearning/ug/single-image-super-resolution-using-deep-learning.html</p>Mike Croucherhttps://www.mathworks.com/matlabcentral/profile/authors/20789457tag:www.mathworks.com,2005:Topic/8447712024-02-07T19:14:54Z2024-02-15T16:12:56ZHow many circles do you find in this picture?<p>Can you see them?</p>Chen Linhttps://www.mathworks.com/matlabcentral/profile/authors/6682740tag:www.mathworks.com,2005:Topic/8446262024-02-07T00:51:44Z2024-02-08T01:24:58ZFlipbook Mini Hack<p>I have been procrastinating on schoolwork by looking at all the amazing designs created in the last MATLAB Flipbook Mini Hack! Check out some of my favorite entires in this Instagram post.They are just amazing. The voting is over but what are y'all's personal favorites? Mine is the flapping butterfly, it is for sure a creation I plan to share with others in the future!</p>Hannahhttps://www.mathworks.com/matlabcentral/profile/authors/30846629tag:www.mathworks.com,2005:Topic/8445062024-02-06T17:12:58Z2024-02-07T19:48:35Zawesome sankey plot<p>It is easy to obtain sankey plot like that using my tool:</p><p>https://www.mathworks.com/matlabcentral/fileexchange/128679-sankey-plot</p>Zhaoxu Liu / slandarerhttps://www.mathworks.com/matlabcentral/profile/authors/18192500tag:www.mathworks.com,2005:Topic/8445012024-02-06T16:58:34Z2024-02-06T16:58:34Zrose bouquet for MATLABer<p>code is here
https://www.mathworks.com/matlabcentral/fileexchange/154496-rose-bouquet</p><p>You can also see the animated version of the competition here
https://www.mathworks.com/matlabcentral/communitycontests/contests/6/entries/14747</p>Zhaoxu Liu / slandarerhttps://www.mathworks.com/matlabcentral/profile/authors/18192500tag:www.mathworks.com,2005:Topic/8444012024-02-06T11:38:57Z2024-02-15T19:17:27ZIs struct harmful for MATLAB projects?<p>Struct is an easy way to combine different types of variants. But now MATLAB supports classes well, and I think class is always a better alternative than struct. I can't find a single scenario that struct is necessary. There are many shortcomings using structs in a project, e.g. uncontrollable field names, unexamined values, etc. What's your opinion?</p>Xiang Xuhttps://www.mathworks.com/matlabcentral/profile/authors/18133750tag:www.mathworks.com,2005:Topic/8443062024-02-05T03:05:36Z2024-02-07T16:29:10ZUse MATLAB to draw a dragon!!<p>function dragon24
% Copyright (c) 2024, Zhaoxu Liu / slandarer
baseV=[ -.016,.822; -.074,.809; -.114,.781; -.147,.738; -.149,.687; -.150,.630;
-.157,.554; -.166,.482; -.176,.425; -.208,.368; -.237,.298; -.284,.216;
-.317,.143; -.338,.091; -.362,.037;-.382,-.006;-.420,-.051;-.460,-.084;
-.477,-.110;-.430,-.103;-.387,-.084;-.352,-.065;-.317,-.060;-.300,-.082;
-.331,-.139;-.359,-.201;-.385,-.262;-.415,-.342;-.451,-.418;-.494,-.510;
-.533,-.599;-.569,-.675;-.607,-.753;-.647,-.829;-.689,-.932;-.699,-.988;
-.639,-.905;-.581,-.809;-.534,-.717;-.489,-.642;-.442,-.543;-.393,-.447;
-.339,-.362;-.295,-.296;-.251,-.251;-.206,-.241;-.183,-.281;-.175,-.350;
-.156,-.434;-.136,-.521;-.128,-.594;-.103,-.677;-.083,-.739;-.067,-.813;-.039,-.852];
% ๅบ็กๆฏไพใไธ่ฒๆนๅผๆฐๆฎ
baseV=[0,.82;baseV;baseV(end:-1:1,:).*[-1,1];0,.82];
baseV=baseV-mean(baseV,1);
baseF=1:size(baseV,1);
baseY=baseV(:,2);
baseY=(baseY-min(baseY))./(max(baseY)-min(baseY));
N=30;
baseR=sin(linspace(pi/4,5*pi/6,N))./1.2;
baseR=[baseR',baseR'];baseR(1,:)=[1,1];
baseR(5,:)=[2,.6];
baseR(10,:)=[3.7,.4];
baseR(15,:)=[1.8,.6];
baseT=[zeros(N,1),ones(N,1)];
baseM=zeros(N,2);
baseD=baseM;
ratioT=@(Mat,t)Mat*[cos(t),sin(t);-sin(t),cos(t)];
% ้ ่ฒๆฐๆฎ
CList=[211,56,32;56,105,166;253,209,95]./255;
% CList=bone(4);CList=CList(2:4,:);
% CList=flipud(bone(3));
% CList=lines(3);
% CList=colorcube(3);
% CList=rand(3)
baseC1=CList(2,:)+baseY.*(CList(1,:)-CList(2,:));
baseC2=CList(3,:)+baseY.*(CList(1,:)-CList(3,:));
% ๆๅปบๅพ็ช
fig=figure('units','normalized','position',[.1,.1,.5,.8],...
'UserData',[98,121,32,115,108,97,110,100,97,114,101,114]);
axes('parent',fig,'NextPlot','add','Color',[0,0,0],...
'DataAspectRatio',[1,1,1],'XLim',[-6,6],'YLim',[-6,6],'Position',[0,0,1,1]);
% ๆ้ ้พๆฏไธช้จๅๅฅๆ
dragonHdl(1)=patch('Faces',baseF,'Vertices',baseV,'FaceVertexCData',baseC1,'FaceColor','interp','EdgeColor','none','FaceAlpha',.95);disp(char(fig.UserData))
for i=2:N
dragonHdl(i)=patch('Faces',baseF,'Vertices',baseV.*baseR(i,:)-[0,i./2.5-.3],'FaceVertexCData',baseC2,'FaceColor','interp','EdgeColor','none','FaceAlpha',.7);
end
set(dragonHdl(5),'FaceVertexCData',baseC1,'FaceAlpha',.7)
set(dragonHdl(10),'FaceVertexCData',baseC1,'FaceAlpha',.7)
set(dragonHdl(15),'FaceVertexCData',baseC1,'FaceAlpha',.7)
for i=N:-1:1,uistack(dragonHdl(i),'top');end
for i=1:N
baseM(i,:)=mean(get(dragonHdl(i),'Vertices'),1);
end
baseD=diff(baseM(:,2));Pos=[0,2];
% ไธปๅพช็ฏๅๆ่ฝฌใ่ฟๅจ่ฎก็ฎ
set(gcf,'WindowButtonMotionFcn',@dragonFcn)
fps=8;
game=timer('ExecutionMode', 'FixedRate', 'Period',1/fps, 'TimerFcn', @dragonGame);
start(game)
% Copyright (c) 2023, Zhaoxu Liu / slandarer
set(gcf,'tag','co','CloseRequestFcn',@clo);
function clo(~,~)
stop(game);delete(findobj('tag','co'));clf;close
end
function dragonGame(~,~)
Dir=Pos-baseM(1,:);
Dir=Dir./norm(Dir);
baseT=(baseT(1:end,:)+[Dir;baseT(1:end-1,:)])./2;
baseT=baseT./(vecnorm(baseT')');
theta=atan2(baseT(:,2),baseT(:,1))-pi/2;
baseM(1,:)=baseM(1,:)+(Pos-baseM(1,:))./30;
baseM(2:end,:)=baseM(1,:)+[cumsum(baseD.*baseT(2:end,1)),cumsum(baseD.*baseT(2:end,2))];</p><pre> for ii=1:N
set(dragonHdl(ii),'Vertices',ratioT(baseV.*baseR(ii,:),theta(ii))+baseM(ii,:))
end
end
function dragonFcn(~,~)
xy=get(gca,'CurrentPoint');
x=xy(1,1);y=xy(1,2);
Pos=[x,y];
Pos(Pos>6)=6;
Pos(Pos<-6)=6;
end
end</pre>Zhaoxu Liu / slandarerhttps://www.mathworks.com/matlabcentral/profile/authors/18192500