Answered
Repeat a string with a delimiter
A = 'abc'; B = join(repmat({A},1,3),', '); B = B{1} C = join(repmat(string(A),1,3),', ') % string output! D = sprintf('%1$s,...

5 years ago | 0

Answered
Remove parenthesis and the contents inside from a string
A = 'abc (ABC)'; B = regexp(A,'^\w+','once','match')

5 years ago | 0

| accepted

Answered
Programmatically change function input
Using a character vector is entirely the wrong approach. The correct approach is to use a comma-separated list: tt = synchroniz...

5 years ago | 0

| accepted

Answered
how can I display 3 row vectors as column vectors in front of eachother using fprintf?
a = [1,2,3]; b = [11,22,33]; c = [111,222,333]; fprintf('%d %d %d\n',[a;b;c])

5 years ago | 0

| accepted

Answered
Find rows in cell for each array between two values and create new cell with the values you just found
Using linear indexing to access the cell arrays only requires one loop: n_new = cell(size(n)); for k = 1:numel(n) idx = f...

5 years ago | 0

| accepted

Answered
How to multiply matrices using for loop?
z = 1; for k = 1:100 y = x.out(:,:,k); w = diag(fastexp(x.db(k))); z = z * y * w * y'; end

5 years ago | 0

| accepted

Answered
Create a new array by summing the columns of old array
The MATLAB approach, where M is your matrix: new = M(:,1:2:end) + M(:,2:2:end);

5 years ago | 0

| accepted

Answered
Reorder Matrix Rows from the row with the most nonzero elements to the row with the least nonzero elements
A = [... 0 1 2 4 7 12 17 22 27 33 42 0 0 1 3 6 11 16 21 26 34 43 0 1 2 4 7 12 17 22 28 35 44 0 0 1 2 8 13 18 23 29 36 45...

5 years ago | 0

Answered
extract decimal number from a file name
The most efficient solution by far: C = {'NNN_2.5C3C_BlaBla'; 'NNN_2.5C3.5C_BlaBla'}; M = sscanf([C{:}],'%*[^_]_%fC%fC_',[2,In...

5 years ago | 0

Answered
string to double conversion
Current = '+5.004100E-07,+5.006900E-07,+5.003900E-07,+5.003100E-07,+5.003300E-07,+5.003700E-07,+5.004800E-07,+5.003200E-07,+5.00...

5 years ago | 0

| accepted

Answered
Undefined function 'cost' for input arguments of type 'char'.
cost I(:,i)=alpha+(beta.*P)+(gamma.*P.*P); % ^ remove this space character total Cost_iteration(i,1)=sum(costI(:,i)); % ...

5 years ago | 0

Answered
How can I create a list of files of the defined typ that are included in the folder?
folder = '...'; typ = 'm'; T = sprintf('*.%s',typ); G = genpath(folder); F = regexp(G,'[^:]+','match'); C = cell(size(F)); ...

5 years ago | 1

| accepted

Answered
Why I cannot create a function handle composed of a sum of function handles in a cell with a vector input?
x = 0:0.01:pi; %Input vector n = 5; %order m = 0:n; %Positive modes %My exam...

5 years ago | 0

| accepted

Answered
??!>>>Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Do NOT use the installation folder of ANY application for your current folder: Trying to save/alter files in the installation...

5 years ago | 0

| accepted

Answered
How do I sort data in a table in ascending order given specific Series type in Column
Either data = sortrows(data,{'Series','Year'}) or data = sortrows(data,{'Year','Series'}) depending on what you expect the o...

5 years ago | 0

Answered
Row and Cloumn find in cell array
What you want is actually the cell index and the index of the cell content, not the "row and column" index as you wrote. f = {[...

5 years ago | 0

Answered
extracting numbers with decimal places from the body of text file and assigning to a variable
%str = fileread(..) % <- simpler way to import the file data. str = sprintf('%s\n','Header with text and comments','other text ...

5 years ago | 1

| accepted

Answered
Loop does not save intermediary steps
"Loop does not save intermediary steps" because nothing in your code makes any attempt to save them. Because each diagonal has ...

5 years ago | 0

| accepted

Answered
interpn vs griddata, not producing the same results when interpolation is only in 2 dimensions
Your code seems to have some bugs: the first and second dimensions should NOT be included in the indices for griddata (i.e. the...

5 years ago | 0

Answered
Creating dynamic variables using loops | Automatic Variables using loops
"How do I bypass this without creating variables using loops." Here is a simple solution using basic MATLAB operations, no bad ...

5 years ago | 2

Answered
How to extract valid and invalid values from 1 array into 2 new arrays?
The loop does nothing, get rid of it. Using find will not solve your problem. The actual problem is that your logic for either ...

5 years ago | 0

Answered
Creating a for loop that calls to a separate function script and collects outputs in vector
One simple approach: cnt = 0; Results = nan(n*n,7); % preallocate 10000x7 for ii = 1:n for jj = 1:n cnt = cnt+1...

5 years ago | 0

| accepted

Answered
Define new operations for a matrix
x = [0,1,2,0,1,0,3,1,0]; y = x.'; V = 0:3; % define value range of multiplication table M = [0,1,2,3;1,0,3,2;2,3,0,1;3,2,1,0]...

5 years ago | 0

| accepted

Answered
Is there a readfile() function in Matlab?
Perhaps they meant this third-party function: https://www.mathworks.com/matlabcentral/fileexchange/68780-readfile/ To get a co...

5 years ago | 0

| accepted

Answered
Continuous Loop operation with conditional statements in table and then calculation
No need to use a loop: T = [1317;1327;1342;1390;1391;1392;1393;1446;1453;1464;1491;1607;1608;1609]; D = diff([false;diff(T)==1...

5 years ago | 0

| accepted

Answered
Recoding unique numbers to another number
The simple and efficient MATLAB solution: X = [5,5,6,6,6,11,11]; [~,~,Z] = unique(X,'stable')

5 years ago | 0

| accepted

Answered
Two numbers that should be equal are not, fractional part showing different values after 17th fractional digit
"Why does this happen? What could have caused such imprecision during calculation?" Operations on binary floating point numbers...

5 years ago | 3

| accepted

Answered
How to change big fractions in small numbers in command windows
syms s S u=(4*s)-(3*sym(pi)); v=(s^2)+(sym(pi)^2); f(S)=u/v; ilaplace(f(S))

5 years ago | 1

Answered
How to create a categorical variable with a specified number of characters?
labels = [repmat('N',1883,1);repmat('A',332,1)]; or less robustly: labels( 1:1883,1) = 'N'; labels(1884:2215,1) = 'A'; % ...

5 years ago | 0

| accepted

Answered
Profiling of inefficient recursive Fibonacci series function
Perhaps something like this: [val,vec] = fibo(6) function [f,t] = fibo(n) if n <= 2 f = 1; t = f; ...

5 years ago | 1

| accepted

Load more