Answered
How to generate sequence numbers
>> N = diff(find([1;diff(A)~=0;1])); >> cell2mat(arrayfun(@(n)(1:n).',N(:),'uni',0)) ans = 1 2 3...

9 years ago | 0

| accepted

Answered
How to make an invisible push button?
See my answer to this question, where I show different ways to do this: <https://www.mathworks.com/matlabcentral/answers/3041...

9 years ago | 0

| accepted

Answered
Subtract a row from a matrix
>> A = [1,2,3;3,5,9;1,8,0;2,3,3]; >> B = [1,8,0]; >> [~,idx] = ismember(B,A,'rows'); >> A(idx,:) = [] A = ...

9 years ago | 0

| accepted

Answered
how to automatically sprintf an array elements
function str = myfun(vec) str = sprintf('.%d',vec); str = str(2:end); end and tested: >> myfun([1,14,20,8]) ...

9 years ago | 2

| accepted

Answered
if is possible to cancel a process if matlab take too much time to perfom the process?
<https://www.mathworks.com/matlabcentral/answers/288185-is-there-a-way-for-breaking-a-loop-iteration-if-it-takes-to-long> <ht...

9 years ago | 0

| accepted

Answered
how do i select a number from a set randomly
V = [-1,+1]; % or any set of values V(randperm(numel(V),1)) % pick one out of the set

9 years ago | 1

Answered
Selecting data from a dynamically named ND array
For a start you might like to read this (if you want to write better code, then it can help you): <https://www.mathworks.com/...

9 years ago | 1

| accepted

Answered
How to solve the loss of values while using the diff function ?
Use <https://www.mathworks.com/help/matlab/ref/gradient.html |gradient|> instead.

9 years ago | 1

Answered
Replacement of Structure array field with array
If |S| is already defined, then C = num2cell(1:10); [S.x] = C{:}; This is a simple application of the comma separate...

9 years ago | 0

| accepted

Answered
How to replace a column with an incremented vector starting at -10?
>> M = rand(12,6); % example data >> col = 4; % specify which column >> M(:,col) = (1:size(M,1))-11 M = 0.5347...

9 years ago | 0

| accepted

Answered
Removing the line number from a numerical matrix
The answer to your question is that you need to use the code that I gave you, and not remove that parts that removes the line nu...

9 years ago | 0

| accepted

Answered
how to find a vector's location in another vector
The simplest and most efficient solution is to use <https://www.mathworks.com/help/matlab/ref/strfind.html |strfind|>: >> a...

9 years ago | 1

| accepted

Answered
How to define function or variable 'x'?
sym('x')

9 years ago | 2

Answered
ERROR Operands to the || and && operators must be convertible to logical scalar values
The inputs to |&&| and |||| must be *scalars*. This means that this is an error: [12,3,4]>2 && [true,false,true] But tha...

9 years ago | 0

| accepted

Answered
Can someone explain this regexp command?
It is quite simple: <Placemark> % match literal string .* % match any characters,...

9 years ago | 0

Answered
Matlab writes wrong matrix to Excel
# Try saving it without transposing the matrix: |...A_proportions')| # Are you sure that you are looking at that exact file?

9 years ago | 0

| accepted

Answered
I have created a gui in.Matlab having multiple radio buttons, I want single radio button selection at a time. Means, I want all other radio buttons unselected when I select one.
You should use a <https://www.mathworks.com/help/matlab/ref/uibuttongroup.html |uibuttongroup|>: that is _exactly_ what it is de...

9 years ago | 0

Answered
Interpolate p1(x1, y1, z1), p2(x2, y2, z2), find x and y when z = 0
>> x1=18.1009988576007; y1=8.98615800401940; z1=+0.0383777665716703; >> x2=18.1467590941979; y2=9.05076591949910; z2=-0.042...

9 years ago | 0

Answered
Remove duplicate rows from matrix
It is trivial to use <https://www.mathworks.com/help/matlab/ref/unique.html |unique|> to get only the unique rows of matrix. Bec...

9 years ago | 5

| accepted

Answered
Error: The size of X must match the size of U or the number of columns of U.
There is no need to make the code slower and more complicated by using |syms| and |eval|. Exactly as I wrote in my answer to <ht...

9 years ago | 2

| accepted

Answered
How can I delete a plot among many other plots?
The cause of this is simple: |categories| is a 9x14 char array. In the loop you use each row of this as the |DisplayName| proper...

9 years ago | 2

| accepted

Answered
How to evaluate inline functions each variable at once?
The simplest solution is to use indexing, and define each function to accept a vector input. Here I used function handles becaus...

9 years ago | 2

Answered
Can I see the contents of a csv file live while matlab is still working on it
This is easy with <https://notepad-plus-plus.org/ Notepad++>: # install the *document monitor* plugin, which checks every thr...

9 years ago | 0

Answered
Finding series of repeating numbers in matrix
>> V = [1,0,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,1,0,0,1]; >> D = [V(1)==0,diff(V==0)]; >> find(D>0) ans = ...

9 years ago | 1

| accepted

Answered
Split matrix into unique bins, find max in each bin
One easy way would be to use <https://www.mathworks.com/help/matlab/ref/cumsum.html |cumsum|> and <https://www.mathworks.com/hel...

9 years ago | 1

| accepted

Answered
How to use gradient?
You need to start reading the MATLAB documentation, because guessing how to use MATLAB will not be an efficient use of your time...

9 years ago | 1

Answered
Finding indices of array elements in 3d matrix
A stab in the dark, but perhaps something like this?: >> W = permute(V,[4,3,2,1]); >> tol = 0.0001; >> idx = any(all(...

9 years ago | 1

| accepted

Answered
i need to pass some data to the fitness function I want to use in GA. Example. ga(@myfit,...) function myfit(ParametersToBeOptimized, externalData)
The simplest way is to define an anonymous function that then calls your fitness function with that data as input arguments. Thi...

9 years ago | 4

| accepted

Answered
How to use conditional statement for this case?
>> x = 1:1:9; >> y = [x(1:3)*2,x(4:6)+2,x(7:9)*3] y = 2 4 6 6 7 8 21 24 27

9 years ago | 0

| accepted

Answered
Error using variable in a function with trial version
You should avoid using the variable name |date|, because this is the name of an inbuilt function <https://www.mathworks.com/help...

9 years ago | 0

| accepted

Load more