Discussion


New in R2021a: Capture disp() output as a string
We've all been there. You've got some kind of output that displays perfectly in the command window and you just want to capture...

5 years ago | 10

Answered
using contour plot to solve the problem
I assume you have an n-by-m matrix of costs for n heights and m radii. I'd use heatmap or imagesc to create a gridded color d...

5 years ago | 0

Answered
audio recording issue with wavrecord function matlab 2020
The error message tells you the problem. error: Unrecognized function or variable 'wavrecord'. Matlab doesn't know what wavre...

5 years ago | 0

| accepted

Answered
Write a MATLAB function that returns the square of a number.
> Is it correct ? funciton square = sqr (x) square = x * x; end Feedback "function" is spelled incorrectly which I'm su...

5 years ago | 2

Answered
How to plot a tiled layout using a loop?
> should a nexttile be in the loop? Yes, but the tiled layout should be defined before the loop. The first two examples list...

5 years ago | 4

Answered
Stop & pause a simulation in app designer using push button
There is no built-in method for pausing a process as of r2021a. Here's how I've achieved this behavior in apps. The main ide...

5 years ago | 5

| accepted

Answered
Most efficient way of creating variables
It's good that you're following that advice. E = [V1(:,10), V2(:,10), . . ., Vn(:,10)]; % most efficient method of this list ...

5 years ago | 0

| accepted

Answered
How to calculate the confidence interval from distributions overlap
It sounds like what you're looking for is to find the number of standard deviations between the mean of the orange distribution ...

5 years ago | 0

| accepted

Answered
how to expand 2D array?
m = [1 2 3 4 5 6 7 8]; y = reshape([[m;nan(size(m))],nan(size(m,2))],2,[]) Version 2 after quest...

5 years ago | 0

| accepted

Answered
filling gaps in time data series with NaN
Compare the original vector of datetime value with the interpolated vector using ismember. This will create a logical vector id...

5 years ago | 0

Answered
Return to GUI after Running Data
There's a line in the GUI code or within one of the callback functions that is closing the GUI figure or making it invisible. Lo...

5 years ago | 1

| accepted

Answered
Extract x,y,z coordinates from figure
Depending on how you plotted the 3D surface, you may already have those coordinates before the plot is produced. For example, ...

5 years ago | 0

Answered
How do I use an if statement to check if a data is present on a excel sheet?
At the top of the documentation page for xlsread there is warning that xlsread is not recommended and it suggests alternative fu...

5 years ago | 0

Answered
Breaking and spliting vector into groups and averaging
timevec = [0 2 3 4 5 0 9 3 4]; chunk = [0 0 0 1 1 1 1 0 0]; g = cumsum([1, diff(chunk)]~=0); % assuming 'chunk' is a row vec...

5 years ago | 2

| accepted

Answered
App designer - display multiple ROI on the same image
I assume "doesn't like this syntax" means that the crosshairs and circle are appearing on a different figure. The reason that...

5 years ago | 1

| accepted

Answered
App Designer - help with syntax for referring to an array's indices
The question is mostly clear and the image is helpful. Interesting approach to align the buttons with the UITable rows - I like...

5 years ago | 1

| accepted

Answered
Use findpeaks on specific frequency range
Limit the range of the peak-search by limiting the inputs. I can't see the x-ticks in your image but this example ignores any...

5 years ago | 0

| accepted

Answered
How do we store the results of a loop vertically?
> Is this a correct way to store the values of a loop vertically in an excel file? CompiledResults(:,i) = Output Well, no. T...

5 years ago | 0

| accepted

Answered
How to merge two timetables with different data and time?
> [T1;T2] is not working and retrns the following error: All tables in the bracketed expression must have the same number of row...

5 years ago | 0

| accepted

Answered
How to have a stack plot with different colors?
To change the axis background color, https://www.mathworks.com/matlabcentral/answers/486181-is-it-possible-to-change-stackedp...

5 years ago | 1

| accepted

Answered
Convert timetable into matrix where time is a variable
A = [minutes(TT.Time), TT.Var1];

5 years ago | 1

| accepted

Answered
How to find standard deviation and mean for this monte-carlo simulation
You either need to store the values within the loop or you can get rid of the loop and use vectorization. N = 100; x = rand...

5 years ago | 0

Answered
3D bar axis label
set(gca,'ytick',1:4,'yticklabel',compose('Pack %d',1:4))

5 years ago | 0

| accepted

Answered
Getting an error that says a variable is not defined in my code, but i have defined it in my function file
Functions have their own workspace (exception:nested functions). Variables are not shared between workspaces unless you explici...

5 years ago | 0

| accepted

Answered
Change color on a single bar
You have to set FaceColor to 'flat'. https://www.mathworks.com/matlabcentral/answers/553894-barcharts-colours-based-on-other-ve...

5 years ago | 2

| accepted

Answered
Find the first and last 1 in each column
X = [NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0 0 0 ...

5 years ago | 0

Answered
Shift columns of a matrix with different values
Method 1: indexing with rem This method shifts values rightward in each row of the nxm matrix A by the amounts specified in vec...

5 years ago | 1

| accepted

Answered
intersection area of 3 or more rectangles
This approach is inspired by the even-odd rule for determining if a point is inside a polygon. If the max left-edge value is sm...

5 years ago | 0

| accepted

Answered
overtop IMAGESC text and change colorbar colors in white for some value of the text
The 0.0% values are rounded to 1dp so any values between -0.049 and 0.049 will show 0.0%. So, you need to find the indices of f...

5 years ago | 1

Answered
subplot aligment automatic method
Method 1: equate axis sizes for all axes after adding colorbar Size of axes without a colorbar will be set to the size of axes ...

5 years ago | 1

| accepted

Load more