Answered
Changing the variable names for multiple tables within a loop that imports the data
Using eval is a misdirection that forces you into writing slow, inefficient, complex code: https://www.mathworks.com/matlabcent...

5 years ago | 0

| accepted

Answered
Second derivative of a function handle
Tip for beginners: whenever you use EVAL you are doing something wrong. With symbolic variables you do not need to define anony...

5 years ago | 0

| accepted

Answered
The logical indices contain a true value outside of the array bounds
As the error states, your logical indexing includes a TRUE value outside the size of that array. Compare: V = randi(9,1,3) X =...

5 years ago | 1

Answered
How to create empty indexes when not available?
data = [2,3,4,5,3,2,4,5]; x = 5; n = 10; p = 2; window = data(max(1,x-n):min(end,x+p)) Are the NaNs really required?

5 years ago | 0

| accepted

Answered
I need help preallocating an array of position vectors
Use a cell array: tmpout = cell(1,stack_size(4)) for frame_no = 1:stack_size(4) .. tmpout{frame_no} = pos; end mat...

5 years ago | 1

| accepted

Answered
Naming new directories sequentially
N = number of directories P = 'absolute/relative path to the parent directory'; for k = 1:N D = sprintf('Prefix_%03d',k);...

5 years ago | 0

| accepted

Answered
accessing multiple individual struct field values
S(1).data = [1;2;3]; S(2).data = [4;5;6]; S(3).data = [7;8;9]; n = 2; V = arrayfun(@(s)s.data(n),S) or (assuming that each ...

5 years ago | 0

Answered
How to loop over different named structs?
cursor_info.Position = [0,1,2,3]; cursor_info1.Position = [1,1,2,3]; cursor_info2.Position = [2,1,2,3]; cursor_info10.Pos...

5 years ago | 1

| accepted

Answered
Sort fields of struct by length and alphabetically
S.aa = rand(3,1); S.bb = 1; S.cc = rand(8,2); S.dd = 1; S.Ee = 1; S.Ff = rand(3,1) Method one: sort and indexing: N = str...

5 years ago | 1

| accepted

Answered
Create Block Toeplitz Matrix
C = {zeros(3),randi(9,3),randi(9,3)}; % {0,B,A} N = 5; X = toeplitz([3,2,ones(1,N-2)]); M = cell2mat(C(X))

5 years ago | 1

Answered
Load .dat files from subfolders with different names
This should get you started. Adapt to suit your data files, folder names, etc.: P = 'absolute/relative path to where the files ...

5 years ago | 0

Answered
Mixed character Tab delimited csv file read in
fm1 = '#%s%[^\n\r]'; op1 = {'CollectOutput',true, 'Delimiter',':'}; fm2 = '"%f%f"'; op2 = {'CollectOutput',true}; hdr = {}; ...

5 years ago | 1

| accepted

Answered
use variable name inside dlmwrite with respect to loop variable
https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html for k = 1:4 M = ... your matrix ...

5 years ago | 1

| accepted

Answered
How do you load m-files that contain filenames with integers and strings?
"...is there a way to use the %d notation in the file names to make this process more efficent?" Of course, the documentation s...

5 years ago | 0

Answered
import file with exponential numbers
You are making this far more complex than it needs to be: M = readmatrix('1.txt')

5 years ago | 1

| accepted

Answered
How to read data out of a .txt-File?
M = readmatrix('temp.txt','HeaderLines',18)

5 years ago | 0

| accepted

Answered
Why matlab gives graph of exp(1/x) and exp(-1/x) wrong?
fun = @(x) exp(-1./x); fplot(fun) ylim([0,10]) fun = @(x) exp(1./x); fplot(fun) ylim([0,10]) I doubt there is much that ca...

5 years ago | 0

| accepted

Answered
Mean Value in a variables cell array
Where C is your cell array: N = size(C,1); M = nan(N,1); for k = 1:N M(k) = mean([C{k,:}]); end

5 years ago | 0

| accepted

Answered
wilcard usage with strncmp
C = {'hello','* 2020','world','* 1923'}; X = ~cellfun(@isempty,regexp(C,'^\* \d{4}$')) D = C(X)

5 years ago | 2

| accepted

Answered
Can't merge tables with error of weird array size limitation, help?
"I want to merge Table B into Table A (rows stay the same, only add the variables) and for identical variables want to keep the ...

5 years ago | 0

| accepted

Answered
Checking whether string exist in a cell and read its ID
The simple, efficient MATLAB approach would be to use ISMEMBER: A = {'banana',12;'orange',23;'apple',35;'peach',74;'pear',51;'c...

5 years ago | 2

| accepted

Answered
How to create a vector by indexing elements within each cell of a 1xN cell array
Where C is your cell array: a = ..; b = ..; F = @(m)m(a,b); V = cellfun(F,C)

5 years ago | 0

| accepted

Answered
How can I read from a file (specific format) using Matlab?
str = fileread('temp.txt'); rgx = ':scurrent:(.+?):t:(.+?):c:(.+?):'; tkn = regexp(str,rgx,'tokens'); tkn = vertcat(tkn{:}) ...

5 years ago | 0

Answered
All possible combination based on 2^n
n = 3; m = dec2bin(0:pow2(n)-1)-'0' % limited precision Or C = cell(1,n); [C{:}] = ndgrid(0:1); C = cellfun(@(a)a(:),C,'uni...

5 years ago | 0

| accepted

Answered
Any value (different values) I enter for TOLERANCE and ITERATION gives the same results(Answer( . It is supposed to give different answers . I don't know why this is occurring.
tol = 0.001; n = 100; f = @(x) (x+1-2*sin(pi*x)); fplot(f,[0,0.5]) a = 0; b = 0.5; pre=0; for i = 1:n c = (a+b)/...

5 years ago | 0

| accepted

Answered
I need to create two test and train folder from one parent folder (in the same directory), I wrote the code, but file couldn't be moved. Please Help!!
P = 'absolute/relative path to where the files are saved'; S = dir(fullfile(P,'*.jpg')); N = numel(files); B = randperm(N) > ...

5 years ago | 1

| accepted

Answered
Using previous value to get the next in for loop
"But this makes my command window seemingly run forever." So far no one has actually addressed why your code is inefficient, in...

5 years ago | 2

Answered
How to reshape a matrix (something that can't be done with reshape function)
A = [1,4,7,10;2,5,8,11;3,6,9,12] nmc = 2; % output number of columns nmr = 3; % output number of rows per "group" B = reshape...

5 years ago | 0

| accepted

Answered
find all sequences between delimiters in an array
v = [1,1,0,2,0,2,1,2,1,1,1,0,2,1,2,0,0,1,1,1,1,1,1,2,1,0]; [begIdx,endIdx,~,match] = regexp(sprintf('%d',v),'2.*?0')

5 years ago | 1

| accepted

Answered
User defined function that evaluates anonymous function with variable number of inputs
Your mistake was deciding to use eval, which is one way that beginners paint themselves into a corner with slow, inefficient, co...

5 years ago | 0

| accepted

Load more