Answered
Using randperm without involving the first and last number
N = 9; [1,1+randperm(N-2),N]

7 years ago | 1

| accepted

Answered
Check if file exists (without having the full name)
You might like to download my FEX submission nextname: https://www.mathworks.com/matlabcentral/fileexchange/64108-next-availabl...

7 years ago | 0

Answered
How to avoid cell2mat while reshaping cell arrays
Simple way using concatenation: C = {rand(55430,2350),rand(55430,2200)}; % fake data D = num2cell(horzcat(C{:}),2); But I gue...

7 years ago | 0

| accepted

Answered
Removing NaNs from a struct
This works for any sized fields (including empty), and gives you the choice of matching ALL or ANY of the fields containing NaN....

7 years ago | 2

| accepted

Answered
round function on complex numbers
This has nothing to do with rounding. Either change the format, e.g.: >> format short g >> a = [1,1,1,1; 1 -j -1 -1; 1 -1 1 -1...

7 years ago | 1

Answered
MyFunction Call generates Error
The problem is that you think that you wrote a function, but you actually wrote a script: https://www.mathworks.com/help/matlab...

7 years ago | 0

Answered
How do I split a string of numbers in n+1th successive intervals and put them in a array or matrix.
>> S = '123456123456123456123'; >> [C,T] = regexp(S,'(\d)\d{0,6}','match','tokens'); >> D = strcat(C(:),vertcat(T{2:end},{''})...

7 years ago | 1

Answered
how would you write a function that operates on both character and numerical arrays
The simple answer to your question is do NOT define B before the loop, i.e.: function B = reverseAppend(vectorVal) % NO B! fo...

7 years ago | 1

| accepted

Answered
How can I mat2cell the array?
>> v = {1,8,1,1,6,1,2,5,3,2,7,11,7,9,10,9}; >> c = regexp(char([v{:}]),'(.).*?(??$1)','match'); >> c = cellfun(@double,c,'uni'...

7 years ago | 0

| accepted

Answered
Undefined operator .^ occurs help!!
"I just wrote everything on the given material" If that is the case then that material is wrong: {} creates a cell array (simi...

7 years ago | 1

| accepted

Answered
Extract data from text file
That is a very badly formatted file. For example, the field delimiters are space characters and space characters also occur with...

7 years ago | 2

| accepted

Answered
Removing specific elements from array
>> a = [1,1,3,5]; >> c = [1,5]; >> [X,Y] = ismember(c,a); >> a(Y(X)) = [] a = 1 3

7 years ago | 1

| accepted

Answered
creating a new column in a matrix using 'if condition"
IF will not help you in this situation. You need to use indexing, e.g.: Reg1(:,10) = a1-b1*Reg1(:,3) + Reg1(:,6); idx = Reg1(...

7 years ago | 0

| accepted

Answered
Converting serial date numbers to datetime array
>> t = datetime(.3718505035,'ConvertFrom','datenum','Format','HH:mm:ss.SSS') t = 08:55:27.883 "also I need to apply the fu...

7 years ago | 0

Answered
How can I create a random array like the example C?
A = [1,1,2,2,7,7,9,9]; B = [3,5,6,8,10,11]; Na = numel(A); Nb = numel(B); Xb = randperm(Nb) % to shuffle the order of B. Xa...

7 years ago | 1

| accepted

Answered
Is there no difference between logical and uint8 regarding disk space (or memory)?
"I understand that binary means 1-bit which consists of 1 and 0." Nope, binary data is stored with one byte per element: https...

7 years ago | 0

| accepted

Answered
Removing unique numbers whilst comparing two structures
A loop and ismember makes this clear and easy. An alternative would be to merge the X and Y data, and then call setdiff in the l...

7 years ago | 1

| accepted

Answered
Help improving the speed of find
Loops, loops, loops... so many loops! Better to vectorize your code: B = 1+sum(bsxfun(@ge,x(:),A),3)

7 years ago | 2

| accepted

Answered
Double Precision is rounding at the 5th digit?
Change the display format., e.g. format long g Although beginners often confuse the two, how data is stored in memory and how ...

7 years ago | 3

| accepted

Answered
two column vector division
"two column vector division" All of your examples use row vectors, not column vectors. "What is a mathematical formula?" See ...

7 years ago | 1

Answered
How does the function contains behave ??
The contains function behaves exactly as I would expect, based on its documentation, which states "If pattern is an array contai...

7 years ago | 0

| accepted

Answered
Adding elements of double arrays inside cell array below another double array inside the same cell array
Concatenating the contents of a cell array is easy using a comma-separated list: >> A1 = cat(1,Sort{1,:}) A1 = 1 2 ...

7 years ago | 1

| accepted

Answered
Index exceeds number of array elements?
On each loop iteration the loop iterator variable R_e is scalar (i.e. it has size 1x1). Inside the function you define i=1 and t...

7 years ago | 0

Answered
Conversion of multidimensional cell into string
Using Guillaume's cell array defined above: >> C(:,2) = cellfun(@(v)char(v+'0'),C(:,2),'uni',0) C = 2 '010' 73 '01...

7 years ago | 1

| accepted

Answered
Load multiple struct 1x1 mat files
It is recommended to load into an output variable, rather than directly into the workspace. doing so also makes your task simple...

7 years ago | 0

| accepted

Answered
A command like "unique" for matrices?
A general solution that does not concatenate the data and works for any size arrays: % Fake data: A = [1;2;3]; B = [1;2;3]; ...

7 years ago | 1

| accepted

Answered
How can i seperate a string in all possible smaller ones without using for loops;.
>> a = 'ATGCA'; >> n = 2; >> x = hankel(1:n,n:numel(a)).'; >> b = num2cell(a(x),2) b = 'AT' 'TG' 'GC' 'CA'

7 years ago | 1

| accepted

Answered
Function day not working
''Unable to use a value of type 'datetime' as an index.'" That error message makes it quite clear: you have a variable in the w...

7 years ago | 2

| accepted

Answered
Convert cell arrays to 4-D array
Where C is your cell array: M = cell2mat(permute(C,[4,3,2,1]))

7 years ago | 1

Answered
Simultaneous Changing of Values in For Loop.
Usually it is much easier to increment over indices, not data: t0 = 0; t = t0; Iv = 1:1:3; Jv = 2:1:4; for x = 1:numel(Iv)...

7 years ago | 1

| accepted

Load more