Answered
count number of ones in binary matrix
Simplest and most efficient answer: nnz(A)

9 years ago | 2

Answered
Select specific data with conditions from struct ?
vec = [data.value]; idx = strcmp('t1',{data.name}) & vec>0.5 & vec<0.8; out = data(idx); giving: >> out.name ...

9 years ago | 0

| accepted

Answered
Convert a string containing a fraction into a number in a fraction format
Much simpler and faster is to use <https://www.mathworks.com/help/matlab/ref/sscanf.html |sscanf|> and simple two-element numeri...

9 years ago | 1

Answered
how to the average of specific subsets on a matrix?
>> M = rand(96,1); % your data matrix >> mean(reshape(M,3,[]),1)

9 years ago | 0

| accepted

Answered
how to continue code in next line with comment between them
All you need is an <https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html ellipsis> on ...

9 years ago | 2

| accepted

Answered
How to take a hex value as user input?
No, MATLAB does not accept HEX literals. You can specify HEX in a string/char array. <https://www.mathworks.com/matlabcentral...

9 years ago | 0

| accepted

Answered
How to avoid Globals on a code created (complex) Figure?
One popular choice is to use <https://www.mathworks.com/help/matlab/ref/guidata.html |guidata|>... however if you are writing yo...

9 years ago | 1

| accepted

Answered
How to replace negative elements in a Matrix with zeros?
The simplest way is to use max: A = max(A,0) For example: >> A = [2, 3, -1, 5; -1, 4, -7, -3; -6, 0, 3, 9; 7, 6, -3, 8] A =...

9 years ago | 12

| accepted

Answered
How do I count the number of rows in a cell array's cells?
For a cell array of tables: sum(cellfun(@height,newvoldata)) For a cell array of numeric/char/cell/struct arrays: s...

9 years ago | 1

| accepted

Answered
Removing/filtering short periods of a value from a vector
>> V = [1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 1 1 1 1 1] V = 1 1 1 1 1 1 1 0 0 0 0 ...

9 years ago | 1

| accepted

Answered
How to split a numrical-charcater String
>> S = 'R88L1R607L10R1293'; >> C = regexp(S,'([RL])(\d+)','tokens'); >> C = [C{:}]; >> C{:} ans = R ans = 88 ...

9 years ago | 0

Answered
What would the code look like to convert a positive decimal (base 10 integer) to its binary form (base 2)?
>> dec2bin(123) ans = 1111011 If you want DIY code, then you will need |mod| and a loop.

9 years ago | 0

Answered
How to add certain rows to a 2D matrix?
>> A = [34,10;23,10;64,10]; >> X = max(A(:,1)); >> M = cell2mat(arrayfun(@(n)(n:X).',A(:,1),'uni',0)); >> M(:,2) = 10...

9 years ago | 1

Answered
Enlarge vector by putting average of surrounding numbers in between of every number of original vector
Without a loop: >> x = [0 2 3 2 1 -1]; >> y = [x;mean([x(1:end-1);x(2:end)]),0]; >> y = y(1:end-1) y = 0.000...

9 years ago | 0

Answered
Output of sprintf - string?
Because MATLAB only introduced the <https://www.mathworks.com/help/matlab/matlab_prog/create-string-arrays.html |string|> class ...

9 years ago | 2

| accepted

Answered
Comparing two different strings
You could use the <https://en.wikipedia.org/wiki/Edit_distance edit distance> as a measure of similarity: >> C = {'live','ev...

9 years ago | 0

Answered
if else in a loop
This syntax does not do what you think it does: modn==2|4 MATLAB will execute these from left to right, giving: (mo...

9 years ago | 1

Answered
How to split a large array of data into several small arrays and store them in a database for future use
Splitting the array into a cell array is easy: >> V = [ 0 0 0 5 9 10 15 18 25 35 22 12 6 2 0 0 0 0 0 0 0 6 5 6 9 15 3 5 2 1...

9 years ago | 1

| accepted

Answered
how to find logbase2(1.3333) and logbase2(1.7279)
log2

9 years ago | 1

| accepted

Answered
Setting the variable range of Slider in GUI
Read the warning message: Warning: 'slider' control cannot have a 'Value' outside of 'Min'-'Max' range Control will not ...

9 years ago | 0

Answered
What is the code for doing a series of processing in images in a folder automatically whenever a new image(or multiple image) appears in a folder in MATLAB
<https://www.mathworks.com/matlabcentral/answers/52326-how-to-listen-to-changes-in-a-directory> <https://www.mathworks.com/ma...

9 years ago | 0

Answered
How can I shuffle a matrix
Here are two methods to rearrange it according to your question. Adjust to suit the size of your matrix. >> A=[1 2 3 4;5 6 ...

9 years ago | 0

| accepted

Answered
what is the reason of this error"Field reference for multiple structure elements that is followed by more reference blocks is an error."
There is no need to use loops and such complicated code. Logical indexing is much simpler: X = all(imrgb==0,3); imrgb(X(...

9 years ago | 0

| accepted

Answered
Replace multiple substrings within a string
*Method one: |for| loop and indexing:* S = 'A' for k = 1:3 C = num2cell(S); C(S=='A') = {'BRARB'}; ...

9 years ago | 2

Answered
How to to group each set of data in individual cell array ?
>> A = [111,1,2,3;111,4,5,6;111,7,8,9;112,10,11,12;112,13,14,15;112,16,17,18]; >> [~,~,X] = unique(A(:,1)); >> B = accum...

9 years ago | 0

Answered
avoid loop in this funcion
Your code randomly swaps adjacent pairs of elements of |x|. This can be done without a loop: function x = shufflepairs(x) ...

9 years ago | 0

Answered
How to extract strings with varied length by regular expression?
>> regexp('2018_a_myid_the_here','(?<=^\d+_[a-z]_)[a-z]+','match') ans = 'myid' >> regexp('2018_b_yourid_t_here'...

9 years ago | 0

| accepted

Answered
Should I use an inline function if it is called large(69120000) no of times?
Read this to know the relative performance of different kinds of MATLAB functions (inline is fastest): <https://www.mathworks...

9 years ago | 0

Answered
How do I set every other number in an array to a specific number with one line?
>> M = zeros(5); >> M(1:2:end) = 100 M = 100 0 100 0 100 0 100 0 100 0 100 ...

9 years ago | 0

| accepted

Answered
Matrix with numerical sequence
N = 7; % must be odd M = ones(N)*16; M(1:2:N,:) = 4; M(2:2:N*N) = 8; M(:,[1,N]) = M(:,[1,N])/2; M([1,N],:) = M(...

9 years ago | 1

| accepted

Load more