Answered
Adds one element in vector from another, by position in array
x = 1:100; % superfluous square brackets removed. y = x(3:end-1)+x(4:end) % the MATLAB way.

5 years ago | 0

| accepted

Answered
How to turn a string into a line of differential equation for ode45?
Ugh, do NOT use eval for this! If the string is actually a symbolic expression then use odeFunction as Walter Roberson stated. ...

5 years ago | 1

Answered
Comparing cell arrays and creation of subfolders
A much more robust approach using absolute filenames (rather than buggy and slow CD) and function syntax rather than outdated co...

5 years ago | 0

Answered
For loops for functions that create structure arrays.
Your indexing throws an error because beta_list has only one column but you are trying to access columns 2 to 61, which don't ex...

5 years ago | 0

Answered
How to create an N-ary array
N = 4; K = 3; C = cell(1,K); [C{:}] = ndgrid(1:N); M = reshape(cat(K+1,C{:}),[],K) How it works: https://www.mathworks.com...

5 years ago | 0

Answered
Hex 01A9 to 16-binary?
No loops, no padding, works correctly for any number of hex digits (not just 16 bits): H = '01A9'; B = reshape(dec2bin(sscanf(...

5 years ago | 1

Answered
How to modify a list of filenames in a specific way?
S = ["vul1_4_9.txt" "bat1_1_1.txt" "chy1_1_16.txt" "chy1_1_17.txt" "g6_1_18.txt" "stcv1_1_1.txt" "...

5 years ago | 0

| accepted

Answered
Import matrices with same name and dimensions from different Data
"What should i do ?" Load into an output variable, not directly into the workspace. Loading into an output variable will avoid...

5 years ago | 0

Answered
Summing Datenum resets after 24 hours
As Steven Lord wrote, serial date numbers are not the right tool for the task: amongst other things you will struggle against de...

5 years ago | 0

| accepted

Answered
How to import multiple .mot files?
S = dir(filePattern); for k = 1:numel(S) F = fullfile(S(k).folder, S(k).name); fprintf('Now reading %s\n', F); S...

5 years ago | 0

Answered
Saving an imported.txt file as .mat file in a for loop using the same original file name
[~,old] = fileparts(File_Struct(K).name); % remove file extension new = sprintf('%s.mat',old); % add .mat file e...

5 years ago | 0

| accepted

Answered
Sort rows of a table based on vector
The MATLAB approach: new_table = stim_sheet(a,:)

5 years ago | 0

Answered
Conditional loop to loop until result is an integer.
As it is currently implemented that algorithm will not work because it does not take into account the behavior of binary floatin...

5 years ago | 1

| accepted

Answered
How to load data from csv-files with "dot"-structured variable names and convert to struct/table?
Better than evil EVAL is to use more robust SETFIELD and a comma-separated list: str = 'in.sensors.temp.x'; val = pi; tmp = r...

5 years ago | 1

| accepted

Answered
Brace indexing error maybe complex ?
"I can't get ride of, i don't see where i do something wrong." You assign the content of the fourth cell of Answer to variable ...

5 years ago | 0

| accepted

Answered
Compare strings of different size/length
in1 = 'Class music n. 12 160b'; in2 = {'Classical musical n. 12 160beats','Techno music n. 7 120beats','Rock disco n. 12 140bea...

5 years ago | 0

Answered
Find, sort and assign values in matrix
q3 = [ 1.0000 2.0000 90.0000 4.9424 2.0000 3.0000 91.0000 4.3018 3.0000 4.0000 92.0000 ...

5 years ago | 0

Answered
plotting using for loop
"...can some body tell me what i am doing wrong or if i am missing something in my code." The main problem is that you are not ...

5 years ago | 0

Answered
I would like to create an array of cos*n*x with n=0,1,2,3...N...
Why do you need a loop? L = 51; N = (L-1)/2; A = cos((0:N)*pi)

5 years ago | 1

| accepted

Answered
convert binary string into hex
str = '0101010011101010'; fun = @(s)dec2hex(bin2dec(s)); out = regexprep(str,'.{1,4}(?=(.{4})*$)','${fun($&)}')

5 years ago | 3

Answered
How to plot e^(-2n)
f = @(x)exp(-2*x); fplot(f)

5 years ago | 0

| accepted

Answered
load multiple files in right order
You could download my FEX submission natsortfiles: https://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-fil...

5 years ago | 0

| accepted

Answered
I have a loop that generates a new matrix with each iteration. How do I store the matrix for each iteration?
Use a cell array: C = cell(1,N); for i = .. your loop C{i} = .. end https://www.mathworks.com/help/matlab/matlab_prog/a...

5 years ago | 0

| accepted

Answered
How to sort numbers in a char
str = 'Y([4.1689],u1+[9.0615],[0.024204])+G([0.2594],u1+[3.8532],[0.31232])+G([1.1277],u1+[2.9793],[0.3143])+D([1.2424],u1+[1.59...

5 years ago | 0

| accepted

Answered
How to create matrix 10x10 with same diagonal vector and empry value
M = toeplitz([2,1,zeros(1,8)])

5 years ago | 0

| accepted

Answered
sum of row in pattern
Data = [1,4,0.0000; 2,7,0.0000; 3,9,0.0000; 4,5,0.1760; 4,6,0.1580; 5,7,0.3060; ...

5 years ago | 0

Answered
How to identify partial string duplicates in a table
Actually the identical part at the start of the string is '*Endo', and this is easy to find: >> X = logical(cumprod(all(diff(Ta...

5 years ago | 0

Answered
Organize vector, extract indices
A = [2,4]; B = [2,70,8,29,98,100]; Out = setdiff(1:numel(B),A)

5 years ago | 0

| accepted

Answered
How to pass multiple arguments to a function stored in a vector?
The solution is to use a cell array for the input values, for example: C = cell(1,N); for k = 1:N % do NOT use i str = in...

5 years ago | 0

| accepted

Answered
Multiple plots in a for loop combined with variable cell arrays
By default every plot call deletes the contents of the figure before plotting the new data. So if you want to call plot multiple...

5 years ago | 0

| accepted

Load more