Answered
Combine (by adding) rows with the same entry in one of the columns
Use <http://www.mathworks.com/help/matlab/ref/unique.html |unique|> and <http://www.mathworks.com/help/matlab/ref/accumarray.ht...

10 years ago | 0

| accepted

Answered
how to use regexp in a more complex example
In two regexp calls: >> selected_motor = [1111,4444]; >> C = {'1111 1-2-3';'2222 1-2-3';'3333 4-5-6';'4444 7-8-9';'4444 ...

10 years ago | 1

| accepted

Answered
Extract curve value from a gray Image
Try one of these FEX submissions: <http://www.mathworks.com/matlabcentral/fileexchange/7173-grabit> <http://www.mathworks....

10 years ago | 1

Answered
How do I underline in fprintf?
<http://www.mathworks.com/help/matlab/ref/fprintf.html |fprintf|> and <http://www.mathworks.com/help/matlab/ref/sprintf.html |sp...

10 years ago | 3

Answered
How do I create a array from two arrays with one of them being the decimals?
>> whl = [11,22,33,44]; >> frc = [12,34,56,73]; >> sscanf(sprintf('|%d.%d',[whl;frc]),'|%f') ans = 11.120 ...

10 years ago | 1

Answered
fname = Sprintf of the file name
The problem is how you are generating the names does not take into account the zeros on the left and right of the non-zero digit...

10 years ago | 1

Answered
How to filter a matrix?
A = randi(9,6,20) % example matrix of integers N = 10; % pick how many values to keep [B,C] = sort(A,2); B(:,1:end-N)...

10 years ago | 0

| accepted

Answered
Using a slider to control a plot.
You should be able to adapt these to your needs: <http://www.mathworks.com/matlabcentral/fileexchange/1670-scrolling-plot-dem...

10 years ago | 2

Answered
Matrix dimensions must agree.
On that line instead of the <http://www.mathworks.com/help/fixedpoint/ref/mrdivide.html right-matrix division> operator (which d...

10 years ago | 0

| accepted

Answered
Why looping just save the last value, not every loop ?
Try using a separate vector to store the values: V = 60:60:300; C = cell(size(V)); for k = 1:numel(V) filename...

10 years ago | 0

| accepted

Answered
How do i set pairs(like (5,6)) instead of single values(like 5) on x-axis?
>> plot(rand(3)) >> set(gca,'XTick',1:3,'XTickLabel',{'(1,2)','(3,4)','(5,6)'}) <</matlabcentral/answers/uploaded_files/...

10 years ago | 0

| accepted

Answered
Sorting a matrix from smallest to biggest left to right
The trick is to transpose, then use the columnwise element order: >> M = [4,7;5,8;6,9] M = 4 7 5 ...

10 years ago | 1

Answered
fraction 3d matrix of 3d matrix
Use <http://www.mathworks.com/help/matlab/ref/mat2cell.html |mat2cell|>: >> inp = rand(2,108,401); >> out = mat2cell(inp...

10 years ago | 0

| accepted

Answered
How to manipulate arrays inside a cell array?
Perhaps you should try something like this: X = cellfun(@(m)m(:,1)>0,C,'UniformOutput',false); D = cellfun(@(m,x)abs...

10 years ago | 0

| accepted

Answered
Repeating blocks of N rows M times
As long as the numbers of rows of |A| is divisible by |N|, then this one line solves the task: >> A = [1,2,3; 4,5,6; 7,8,9;...

10 years ago | 2

Answered
Sort matrix based on unique values in one column
[~,idx] = sort(mat(:,1)); % sort just the first column sortedmat = mat(idx,:); % sort the whole matrix using the sort ind...

10 years ago | 23

| accepted

Answered
Create matrix with periodic increments
The function <http://www.mathworks.com/help/matlab/ref/bsxfun.html |bsxfun|> is really handy for these kind of tasks: >> X ...

10 years ago | 1

| accepted

Answered
How to undo an accepted answer?
*EDIT*: recent changes to MATLAB Answers allow the original question poster to un-accept an answer. # It is possible for th...

10 years ago | 0

Answered
how many times a string is present in a cell array
Here it is in just three lines of code, no loops, and no third-party functions: a = {'2';'23';'231';'2312';'23121';'231213'...

10 years ago | 1

| accepted

Answered
I get this error line, 'Attempted to access (Matrix), index must be a positive integer or logical.'
Have a look at your definitions of |row| and |col|: row = ((lon(i)) - (min(lon)))/((max(lon)) - (min(lon))) * 100 + 1 a...

10 years ago | 0

Answered
I have to sum two matrix with different dimension, for example Px = [3x3] and Py = [6x6], how can I insert elements on the diagonal of Px between P11 and P22 for example to make it of the same dimension of Py?
>> v = [-Inf,+Inf,NaN]; >> Px = [1,2,3;4,5,6;7,8,9]; >> N = 2*size(Px,1); >> P = zeros(N); >> P(1:2:end,1:2:end) ...

10 years ago | 0

Answered
Why am i getting unusual plots when using the sin() and cos() function?
It is not unusual at all: you are calculating with _even multiples of pi_, with some floating point errors added into the mix. W...

10 years ago | 2

Answered
find() doesn't work until viewing variable.
_"I'm almost certain the cell is exactly 0.22"_ No it isn't. And that is likely part of the problem. I can't explain why i...

10 years ago | 1

| accepted

Answered
How to define an array within a loop. I am trying to calculate and store some variables provided some conditions are true.Can someone please tell me how to correctly define array x(i,j) for this?
MATLAB is not some low-level language like C, so you do not need to solve everything with ugly loops and |if| statements. Learn ...

10 years ago | 0

| accepted

Answered
Input A of class cell and input B of class cell must be cell arrays of strings, unless one is a string".
The message seems quite clear: you are providing a cell array to <http://www.mathworks.com/help/matlab/ref/ismember.html |ismemb...

10 years ago | 0

| accepted

Answered
How to change the exponent number in my answer
One option is to experiment with the <http://www.mathworks.com/help/matlab/ref/format.html |format|> options: >> format lon...

10 years ago | 0

| accepted

Answered
Why this always ask to preallocating
The purpose of array preallocation is explained quite thoroughly in the documentation: <http://www.mathworks.com/help/matlab/...

10 years ago | 1

| accepted

Answered
Change the dimension of an output matrix
You can use |permute| and |reshape|: >> inp(:,:,3) = [0,1;2,3]; % page 3 >> inp(:,:,2) = [4,5;6,7]; % page 2 >>...

10 years ago | 0

Answered
How to organize text files by date and time inside folder
% Create some fake filenames: V = now - [0:0.987654321:10].'; fmt = 'DDDD-DD-mm-yyyy_HH-MM-SS'; C = cellstr(datestr(V...

10 years ago | 1

Answered
How to add value at end of row in a matrix
Without any loops: R = [2;4;5;2]; C = [1;3;6;7]; [~,X] = sort(R); [~,~,Y] = unique(R); Z = accumarray(Y,ones(si...

10 years ago | 0

| accepted

Load more