Answered
How to combine series of consecutive numbers in Matlab?
Bs = cellfun(@(v)v(1),s); Es = cellfun(@(v)v(end),s); D = Bs(2:end)-Es(1:end-1); X = cumsum([1,D>=4]); Bz = accuma...

8 years ago | 1

| accepted

Answered
How to access a table using the string from within a cell as part of the dot notation index
datanew.(Z) <https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html>

8 years ago | 0

| accepted

Answered
How to print cell contents into m-file?
>> inputs = {'x' 'y' 'z' 'k'}; >> signs = '**/'; >> C = inputs; >> C(2,1:end-1) = num2cell(signs); >> fprintf('out...

8 years ago | 1

| accepted

Answered
Contourplot with nonuniform data leads to strange interpolation?
There is no need for any interpolation, |griddata|, |meshgrid|, |ndgrid|, or changing the number of points. As long as the data ...

8 years ago | 1

| accepted

Answered
How to write cell array contents into m-file as shown below?
Printing the strings of a cell array to an open file (with id |fid|) is easy, just use a combination of <https://www.mathworks.c...

8 years ago | 1

| accepted

Answered
Removing Rpeated Values from a Matrix
>> M = [518460,3.3220;518460,-12.9840;518520,3.7890;518520,-10.2800;518580,7.6730;518580,16.8510;518640,5.9590] M = 5...

8 years ago | 0

| accepted

Answered
How can I find indices of a vector where the difference between the preceding and current element is x?
>> X = [5,6,7,8,9,134,135,136,137,138,403,404,405]; >> D = diff(find([true,diff(X)>100,true])); >> C = mat2cell(X,1,D); ...

8 years ago | 0

| accepted

Answered
Handling header name variation
*One: Position:* Can you rely on the column position as being fixed? If the position is always the same then you could simply re...

8 years ago | 1

| accepted

Answered
concatenate cell array of cell arrays
Where C is your cell array, all of these are equivalent: [C{:}] horzcat(C{:}) cat(2,C{:}) https://www.mathworks.com/help/mat...

8 years ago | 1

| accepted

Answered
Why there is no space after the equal sign? (fprintf)
_"Why there is no space after the equal sign?"_ It has nothing to do with |fprintf|. As the <https://www.mathworks.com/help/m...

8 years ago | 2

| accepted

Answered
Skip subs/index values with accumarray
Use <https://www.mathworks.com/help/matlab/ref/unique.html |unique|>'s third output to get the indices: [uni,~,idx] = uniqu...

8 years ago | 0

| accepted

Answered
How to vectorize for loops
K = 2; S = size(A); [R,C] = ndgrid(1:S(1),1:S(2)); Z = zeros([K,S]); Z(sub2ind([K,S],A,R,C)) = 1; out = permute...

8 years ago | 0

| accepted

Answered
Help Formatting Vector To Not Include Starting Point
N = 5; vec = linspace(0,2,N+1); vec = vec(2:N);

8 years ago | 0

| accepted

Answered
If statement problem (tip calculator)
I would recommend that you use logical indexing. I will do the first one for you: t = nan(size(x)); idx = x<10; t(idx...

8 years ago | 0

| accepted

Answered
Using regular expressions to ignore files starting with a certain set of characters
Okay, just to make it clear to any one else reading this, that this is a bad idea: <https://www.mathworks.com/matlabcentral/a...

8 years ago | 0

| accepted

Answered
How to edit 2 matrices
>> A = [1;2;3;4;5;6;7;8]; >> B = [1,2;5,8;7,8]; >> C = A(ismember(A,B)); >> [~,I] = sort(C); >> [~,X] = ismember(B...

8 years ago | 0

| accepted

Answered
Illegal use of reserved keyword "for".
Instead of this newLine = '' for n = 1:length(cell{1,1}) You should do this: newLine = ''; for n = 1:length(cell...

8 years ago | 1

Answered
How to subtract elements in a matrix from each other
With some juggling of matrices this can be done with just one line of code: >> A = [30 39 42; 10 15 22; 1 5 7] A = ...

8 years ago | 1

| accepted

Answered
How do I convert a column to numeric?
Where |C| is your cell array: V = str2double(C(:,1)) This assumes that there is no header, and that each cell of the fir...

8 years ago | 2

| accepted

Answered
How to compare two matrix and then count each elements?
Some variety of these might do what you want (although those examples are not very enlightening) >> S = nnz(ismember(A,B))...

8 years ago | 0

| accepted

Answered
What does the string in 'DeleteFcn' evaluate to?
*That is a very badly written piece of code. DO NOT LEARN FROM IT*. Something like this is simpler, clearer, less buggy, and ...

8 years ago | 0

| accepted

Answered
Why the first cell is printed in one row and second in two? (fprintf)
The problem is that the data itself contains newline characters (10=\n): >> +maCell{2}(end) ans = 10 Remove those cha...

8 years ago | 1

| accepted

Answered
decimals and splitting cell arrays
There is no rounding occurring. Change the <https://www.mathworks.com/help/matlab/ref/format.html |format|> to precision with wh...

8 years ago | 0

| accepted

Answered
Find and extract lines from text file
>> str = fileread('protokoll.txt'); >> C = regexp(str,'[^\n\r]+New site no \d+ created[^\n\r]+','match'); >> C{:} ans...

8 years ago | 2

| accepted

Answered
How do I select specific data from a matrix with a loop?
Fundamentally it will come down to indexing into your data matrix |C| (which seems to be a cell array: is this correct?). Here i...

8 years ago | 0

Answered
how to convert a number in exponential form to normal decimal form?
That value is far too large to store in a <https://www.mathworks.com/help/matlab/ref/double.html double> without loss of precisi...

8 years ago | 1

| accepted

Answered
fprintf a long cell array vector into the file
One very simple solution is to put each name on its own line: fprintf(fid,'variablesList: '); fprintf(fid,'%s,...\n',myL...

8 years ago | 1

| accepted

Answered
storing output (which are matrices) of for loops
<https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html Array preallocation> works for me: l = 1; B...

8 years ago | 0

| accepted

Answered
how do i copy one column of a matrix with another column of a matrix in matlab?
Where |C| is your cell array, and |M| the matrix: M(:,1) = [C{:,1}]

8 years ago | 0

Answered
How to convert row to matrix with below format????
>> A = [3,1,1,4]; >> N = numel(A); >> Z = zeros(N); >> Z(sub2ind([N,N],1:N,A)) = 1 Z = 0 0 1 0 1...

8 years ago | 1

| accepted

Load more