Answered
Search for all mat datafiles in directory
Something like this perhaps: D = the root directory; S = dir(fullfile(D,'**','*.mat')); N = {S.name}; F = {S.folde...

9 years ago | 0

Answered
How can I count the number of zeros in a matrix until the value is non-zero?
>> sum(cumprod(A==0,2),2) ans = 2 4 1 0

9 years ago | 2

| accepted

Answered
Call variable to another function without GUI
_" I have a function named example.m in which I have four variables P,S,X and Y. I would like to use the resultant values of P a...

9 years ago | 1

| accepted

Answered
How can I output multiple function outputs in a single vector (accessing all elements of an N-D array in a function)
* You can easily copy |ind2sub| and alter it to return one output. *Do not change the original file.* * You can find some peopl...

9 years ago | 0

Answered
How to read variables from multiple '.tab' file?
This code automatically locates the header lines by checking for the # character at the start of the line, the variable mywant s...

9 years ago | 1

Answered
global variables are fast? Functions make copies or not?
These will be faster than globals and let you access the same data over multiple function calls: # <https://www.mathworks.com...

9 years ago | 2

Answered
How do I fix this function/function handle so my matrix dimensions agree? I have tried every period before operator combination I can think of
Although beginners love throwing parentheses around everything, actually using lots of parentheses makes code more difficult to ...

9 years ago | 1

Answered
plotmatrix - how to change the color according to one variable in data?
plotmatrix(Y(Y(:,1)==1,:),'g'); hold on plotmatrix(Y(Y(:,1)==2,:),'r');

9 years ago | 0

Answered
Sequential or selective access to N Permute K
Have a look at these: <https://www.mathworks.com/matlabcentral/fileexchange/13101-recperms--recursive-permutations-> <http...

9 years ago | 1

| accepted

Answered
How can I multiple the element of cell of array with different size?
>> C = cellfun(@times, A, B, 'UniformOutput',false); >> C{:} ans = 5.4145 ans = 3.1169 2.7072 3.13...

9 years ago | 0

| accepted

Answered
Is it possible to write a function with two different kind of output modes?
Use <https://www.mathworks.com/help/matlab/ref/nargout.html |nargout|>, something like this: function [X,Y] = myfun() if...

9 years ago | 1

| accepted

Answered
How to set a default value for my custom function
Unfortunately MATLAB does not (currently) allow defining default values in the <https://www.mathworks.com/help/matlab/ref/functi...

9 years ago | 5

| accepted

Answered
How to efficiently split a 2-D matrix? (inversion of "vertcat" process).
*Method one: <https://www.mathworks.com/help/matlab/ref/transpose.html |cat|>.* Avoid the whole problem by concatenating along t...

9 years ago | 0

| accepted

Answered
matlab plot three different colors for three different change (red, yellow, blue)
This is MATLAB, so there is no need to use ugly loops or write complicated code. Simple is always best. X = [1,2,3,4,5,6,7,...

9 years ago | 0

Answered
how to get values from a struct
_"How can I extract values for query={'key1','key3'}?"_ cellfun(@(f)s.(f), query, 'uni',0) or using <https://www.mathwork...

9 years ago | 0

| accepted

Answered
Fprintf: how to automatically move to a new line when reach end of screen?
There is no _automatic_ way to do this, but on MATLAB versions before R2014b it was possible to get the command window width: ...

9 years ago | 1

Answered
Wrong result inside a loop
_"matlab returns a wrong value"_ No, it doesn't. It returns exactly the value that you told it to give you. One of your input...

9 years ago | 0

| accepted

Answered
How many times specific element occurs in each column of a given matrix
V = sum(M==0,1) where |M| is your matrix.

9 years ago | 0

| accepted

Answered
Find the precision of a value
No doubt there will be disagreements over what it means for floating point numbers, but here is one solution which provides the ...

9 years ago | 2

| accepted

Answered
Arrange string based on 1 or 0 value
[col,row] = find(F'); fun = @(v){sprintf(', %s',D{v})}; out = accumarray(row,col,[],fun); out = cellfun(@(s)s(3:end),...

9 years ago | 1

| accepted

Answered
Undefined function 'min' for input arguments of type 'struct'.
The <https://www.mathworks.com/help/matlab/ref/load.html |load|> documentation clearly describes that |X| is a structure: X...

9 years ago | 0

Answered
Multidimensional array: how to extract several dimensions at same time?
arrayA(:,:,1,:) as explained in the introductory tutorials and documentation: <https://www.mathworks.com/help/matlab/get...

9 years ago | 0

| accepted

Answered
Remove rows in matrix A if not member of matrix B
MATLAB works best when working on entire arrays at once, whereas using a loop and removing rows like that is inefficient and not...

9 years ago | 0

| accepted

Answered
How to count frequency of non zero elements col wise
>> [N,C] = hist(A,0:3); >> Z = N(C~=0,:).' Z = 2 1 0 0 2 0 0 1 1 0 1 1 2 ...

9 years ago | 1

| accepted

Answered
deleting rows with a criteria for repeating indices
>> B = A(A(:,2)~=2,:); >> X = diff(B(:,2))~=0; >> X = [true;X] | [true;true;X(1:end-1)]; >> C = B(~X,:) C = ...

9 years ago | 1

| accepted

Answered
Compare values in array1 with array2 and store a new value in a new array if match found
>> D = abs(bsxfun(@minus,Array1,Array2(:,1).')); >> [~,X] = min(D,[],2); >> Array3 = Array2(X,2) Array3 = 300 ...

9 years ago | 0

| accepted

Answered
How to distinguish two similar but different strings?
Some ideas: * use |strcmp| instead of |regexp|. * add |^| and |$| to your regular expression. * split the strings and use |...

9 years ago | 0

Answered
Error in converting Cell array to double
<https://www.mathworks.com/help/matlab/ref/str2double.html |str2double|> converts those cell arrays of strings to double: >...

9 years ago | 0

| accepted

Load more