Answered
How do I sort an array in descending order without using the sort function?
Here are a few ways to sort an array of unique values without using |sort|: sortrows(A(:),-1) A(end:-1:1) = unique(A);...

11 years ago | 0

Answered
How to combine signals for each digit in telephone number (dtmf) to form one continuous signal?
Try something like this: Fs = 8000; t = 0.25; N = 1:ceil(t*Fs); % define DTMF: R = [697,770,852,941]; % Hz, row...

11 years ago | 1

Answered
How to write a program in Matlab which takes as input a student’s grade (such as ‘81’) and return a new grade in the A,B,C etc scale?
Or fully vectorized using |histc|: >> inp = [95,16,85,50,75]; % example values >> V = [-Inf,64, 67, 70, 73, 77, 80, ...

11 years ago | 0

Answered
Reducing a matrix size by averaging blocks within the matrix.
You could use <http://www.mathworks.com/help/matlab/ref/conv2.html |conv2|> and select every second element of its output: ...

11 years ago | 1

| accepted

Answered
preserving variable class when extracting fields from a struct
All of that "packing" and "unpacking" is a total waste of time, space and code. Just define those values to be part of the struc...

11 years ago | 0

| accepted

Answered
Saving a variable from a function with a different name
Simple: call that function with that variable name as its output argument: var_name = A(X,Y); will define |var_name| in ...

11 years ago | 0

| accepted

Answered
For loop beginner question
This is what happens when you write a large block of code without checking it as your are writing it. We get many questions from...

11 years ago | 2

| accepted

Answered
Problem with find function
You can use <http://www.mathworks.com/help/matlab/ref/strcmp.html |strcmp|> to obtain the <http://www.mathworks.com/help/matlab/...

11 years ago | 1

| accepted

Answered
Adding matrices to a 3D matrix in a specific order
This is easy using MATLAB indexing. Here is an example with 2D matrices, to show how indexing can be used to insert values in pa...

11 years ago | 1

Answered
Select elements in a cell array
A = [2,3,4]; B = {[1,2,3;4,5,6;1,2,3], [7,3,4;3,2,1], [1,4,5;2,4,6;3,4,7]}; C = {}; for k = numel(B):-1:1 C{k}...

11 years ago | 0

| accepted

Answered
How do I make a cell array of doubles with non-uniform dimensions into a row numeric array? (not a column numeric array)
Following your comment _"It's a 1x1000 cell array, each with a double of between 50x1 and 52x1 in size. I want to either make al...

11 years ago | 0

| accepted

Answered
error using fprintf invalid file identifier use fopen
Your code opens the same file multiple times in a loop, without closing it. Once that file is open there is *no need* to keep op...

11 years ago | 0

Answered
Error using set - XColor and YColor
Here is the official list of all public axes properties: <http://www.mathworks.com/help/matlab/ref/axes-properties.html> A...

11 years ago | 0

Answered
How to create a function with a matrix M as an input
You are told that the function should have _one_ input argument, but then you created a function with _two_ input arguments: |ro...

11 years ago | 1

Answered
How to get digits ( e.g.telephone number) from user and treat each digit separately?
If you get the digits as a string then this is easy by simply subtracting |'0'| from the string: >> S = input('Please enter...

11 years ago | 1

| accepted

Answered
Error in ceil() function?
<http://www.mathworks.com/help/matlab/matlab_prog/floating-point-numbers.html Floating point numbers> are how decimal values are...

11 years ago | 0

| accepted

Answered
How do i find the start and end of a run of numbers?
Use <http://www.mathworks.com/help/matlab/ref/diff.html |diff|> and <http://www.mathworks.com/help/matlab/ref/find.html |find|> ...

11 years ago | 1

| accepted

Answered
how to generalize a nested for-loop?2
@Mnr: try this: V = [1+1i,+1-1i,-1+1i,-1-1i]; W = [0.3,0.2,0.5,0.8]; N = numel(V); X = cell(1,N); [X{:}] = ndgr...

11 years ago | 1

Answered
how to mark the highest white pixel through bottom to the top? using grayscale image.
Very simply without any loops, using <http://www.mathworks.com/help/matlab/matlab_prog/vectorization.html vectorized code>: ...

11 years ago | 1

Answered
Find the indeces of common elements of
You can use <http://www.mathworks.com/help/matlab/ref/bsxfun.html |bsxfun|> quite effectively for this: >> a = [7,10,33]; ...

11 years ago | 0

| accepted

Answered
I need to make a loop that will show and count elements that are smaller that 10 in matrix A
Why do you need a loop? <http://www.mathworks.com/help/matlab/math/matrix-indexing.html MATLAB's indexing> tools are much more p...

11 years ago | 0

Answered
How can I process each line or word in a text file using MATLAB?
Just use <http://www.mathworks.com/help/matlab/ref/textscan.html |textscan|>: fid = fopen('temp.txt','rt'); C = textscan...

11 years ago | 0

| accepted

Answered
How to insert space between strings while doing strcat ?
The most efficient approach is to use sprintf: >> a = 'hello'; >> b = 'world!'; >> sprintf('%s %s',a,b) hello world!

11 years ago | 0

Answered
how to fill with the last non empty value across each column
A = [0 9 7 0 0 ; 0 0 0 6 0;0 2 0 0 0; 8 0 4 2 0] B = A; for k = 2:size(B,1) idx = B(k,:)==0; B(k,idx) = B(...

11 years ago | 0

| accepted

Answered
can't get my ploy function to plot all the vectors at once
MATLAB can be written much more efficiently without loops: function M = myployplotter(n,x) M = bsxfun(@power,x(:),1:n); ...

11 years ago | 0

Answered
index out of bounds
If you want to look up colornames then use my FEX submission |colornames|: <http://www.mathworks.com/matlabcentral/fileexchan...

11 years ago | 0

Answered
MATLAB how to automatically read a number of files
This is a very common question, so we covered it very thoroughly in our wiki: <http://matlab.wikia.com/wiki/FAQ#How_can_I_pro...

11 years ago | 1

Answered
Finding a letter or number in a string of cells
There is no need for any loops: >> X = {'Brad1','Bobby2','1Bob','2Bradley','2Bailey'}; >> X(~cellfun('isempty',strfind(X...

11 years ago | 0

Answered
Printing a cell array of strings and numbers with fprintf?
There is no need for the loops, just transpose the cell array and then use |{:}| to convert it to a <http://www.mathworks.com/he...

11 years ago | 5

| accepted

Answered
How do I create cell/struct array with the specific lines taken from a text file?
*EDIT: See the improved code at the end on this answer* % read the file as a string: str = fileread('images_list1.txt');...

11 years ago | 1

| accepted

Load more