Answered
how to arrange data into array
Without an intermediate sparse array: R = [1;2;3;4]; C = [10;11;13;15]; V = [1e-5;5e-5;10e-5;15e-5]; % S = max([R,C],[],1);...

5 years ago | 0

Answered
How to count the number of times that values changes?
A = [1;1;1;2;1;3;3;1;1] B = [NaN;cumsum(diff(A)~=0)]

5 years ago | 3

| accepted

Answered
Getting rid of loops
Logical indexing is much simpler than using loops: idx = A<1 & A>0; A(idx) = B(idx); A(A<C) = NaN; idy = B>100 | B<0; ...

5 years ago | 0

| accepted

Answered
How to conditionally merge rows in a table
lat = [45.67, 45.67, 56.89, 78.61]'; lon = [-66.45, -66.45, -65, -67]'; id = [202, 202, 201, 200]'; key = {'A', 'B', 'C', 'C'...

5 years ago | 0

| accepted

Answered
Increment components of vector till a desired limit
for k = 6:100 % or 105 maybe... you can check this. v = reshape(hankel(1:5,5:k),1,[]) end

5 years ago | 2

Answered
Expected one output from a curly brace or dot indexing expression but there were 2 results
For your code to work the index tn4 must be scalar, but the error message tells us that it is not. Compare: S(1).blah = 1:3; ...

5 years ago | 1

| accepted

Answered
behaviour of nargout for anonymous functions
You get two different answers because you are testing two different functions: the function handle to addOne an anonymous func...

5 years ago | 0

| accepted

Answered
Combining cell arrays with empty doubles
% slightly more complex example data: a = {[],1;[],[]}; b = {[],[];2,[]}; c = {[],[];[],NaN}; % tmp = cat(3,a,b,c); [~,idp...

5 years ago | 2

| accepted

Answered
How to properly extract dataset and load in new file? Keep getting error.
There is no data field because you saved the array using the name Xs. So you need to use the field Xs (and get rid of the superf...

5 years ago | 0

| accepted

Answered
How do I insert data into new format based on row positions?
data = [8; 7; 1; 5]; datarowpositions = [0; 0; 0; 4; 0; 1; 0; 2; 0; 0; 3; 0]; desired = datarowpositions; desired(datarowposi...

5 years ago | 0

| accepted

Answered
naming using a string function
The MATLAB approach: N = numel(files); C = cell(1,N); for k = 1:N F = fullfile(files(k).folder,files(k).name); C{k}...

5 years ago | 0

Answered
how to iterate?
I don't see why any iterations are required, vectorized code will do this quite easily: A = [-120449852, -107496428]; B = [-10...

5 years ago | 0

| accepted

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

Load more