Answered
Subscript indices must either be real positive integers or logicals.?
You have a variable named |sum|. Clear it: clear sum

9 years ago | 1

| accepted

Answered
What are other types of messages than warnings and errors?
There is no _documented_ way to get arbitrarily colored text in the command window. The only documented features with colored te...

9 years ago | 2

Answered
How do I sort entire columns of an array by a specific row?
@Elias Beaini: your code does not make much sense, and should be revised. For example: * You define |n=1:20|, which means tha...

9 years ago | 1

Answered
Removing double empty lines from a text file
You can easily write the new file at the same time as you read the old one, which is faster and uses much less memory. Here is a...

9 years ago | 0

| accepted

Answered
How to reshape a matrix in a specific way?
Just use |reshape| and |transpose| (where 8 is the required number of columns): >> A = rand(10,4); % fake data >> B = re...

9 years ago | 0

| accepted

Answered
Separating arguments by line break
Adding <https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html ellipses> might help you:...

9 years ago | 0

| accepted

Answered
no repeating numbers in a matrix
Your approach is extremely inefficient. Just use <https://www.mathworks.com/help/matlab/ref/randperm.html |randperm|>: >> V...

9 years ago | 0

Answered
switch case and inequalities
It _is_ possible with |switch|: age = 200; switch true case age>150 disp('that''s impossible!') case ag...

9 years ago | 2

Answered
Trying to flip image without using the built in function
function B = myflipped_image_lr() A = imread('horse.jpg'); figure(1) imshow(A); B = A(:,end:-1:1,:); figure(2) ...

9 years ago | 2

| accepted

Answered
help breaking nested for loop?
|break| should work: it will exit the |for| loop when it is executed, and MATLAB will continue with the rest of the function. If...

9 years ago | 0

Answered
How fix Cell contents reference from a non-cell array object?
The problem is this: for vec_len = 1:size(checked_min_max, 1) ... checked_min_max = []; end Although be...

9 years ago | 0

Answered
move a row from a cell to another cell
Your data: >> Q = cell(3,1); >> Q{1} = [1,2,3,4;11,22,33,4;11,2,33,4]; >> Q{2} = [1,11,11,2;22,2,32,33]; >> Q{3} =...

9 years ago | 0

| accepted

Answered
m-files as function inputs in for loop
One obvious problem is that you are using _command syntax_ whereas you need to be using _function syntax_ (note the parentheses!...

9 years ago | 1

| accepted

Answered
Accessing Nth element of a given field for all elements in a non-scalar structure.
for N=1:10; s(1).x{N} = rand(100,1); s(2).x{N} = 5.*rand(100,1); s(3).x{N} = rand(100,1)./3; % fixed the incorr...

9 years ago | 0

Answered
How to clean up If-Statement
Something like this should get you started: typ = {'psi','GPa','MPa','Pascal'}; csl = sprintf(',%s',typ{:}); pmt = sp...

9 years ago | 0

| accepted

Answered
Replace Missing Data Points in Matrix with Interpolated Points
Download John D'Errico's excellent FEX submission: <https://www.mathworks.com/matlabcentral/fileexchange/4551-inpaint-nans>

9 years ago | 0

Answered
Need help displaying the matrix in Conway's game of life
_"Is there a way to keep the existing matrix open (perhaps not as an image file) and update it live?"_ Create the image as a ...

9 years ago | 0

Answered
Your fitness function must return a scalar value.
The error message refers to the fast that <https://www.mathworks.com/help/gads/ga.html |ga|> requires the objective function to ...

9 years ago | 1

Answered
Fill a zeros matrix with another matrix until it is full
MATLAB is not an ugly low-level language like C++ and does not need loops to solve all tasks: idx = 1+mod(0:numel(y)-1,nume...

9 years ago | 0

| accepted

Answered
How to pass additional inputs to function in 'fminbnd'?
Do NOT call xlsread inside the function! Doing so will result in slow and inefficient code due to repeated file access. The pro...

9 years ago | 3

| accepted

Answered
How to successively fill a vector with for loop?
<https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html Preallocate the output array> and then simply use i...

9 years ago | 0

| accepted

Answered
How do I average specific collumn and specific rows of a matrix?
Where |M| is the old matrix, and |N| the new: N = mean(M(:,7:9),2)

9 years ago | 1

| accepted

Answered
How do I make a file name with combination of two strings ?
Use <https://www.mathworks.com/help/matlab/ref/sprintf.html |sprintf|> and adjust the format string to suit: S1 = 'hello';...

9 years ago | 2

Answered
cell array to matrix
Assuming that the sizes are compatible you can easily use a <https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-l...

9 years ago | 0

| accepted

Answered
Something is wrong with my output...
You forgot that MATLAB is <https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major>: X = 0:pi/16:2*pi; % squ...

9 years ago | 0

| accepted

Answered
How to plot multiline with variable inputs
There is no point in making this so complicated: no slow ugly loop or complex code is required. All you need is plot(x, var...

9 years ago | 0

Answered
There are four char sequences in the name of a matlab variable (say "AaL1.mat" {1} A to I; {2} a to e; {3} low,med,high; {4} 1 to 6 ). How to loop every possible name (from AaL1.mat to IeH6.mat) ?
fmt = '%s%s%s%s.mat'; S1 = 'A':'I'; S2 = 'a':'e'; S3 = 'LMH'; S4 = '1':'6'; for k1 = 1:numel(S1) for k2 = 1:numel...

9 years ago | 1

| accepted

Answered
save to 2nd decimal, then add brackets
A = [1.224,1.338;2.451,-2.367;1.222,4.123]; fdir = '.'; directory name = 'myfile.txt'; fmt = 'B=[%.2f, %.2f;\n(%.2f),...

9 years ago | 0

| accepted

Answered
How to append several elements to a single element in an array?
Much faster and simpler than using |string|, |strjoin|, and |str2double|: >> A = [1 2 3 4 5 6 7 8 9 10]; >> N = sscanf(s...

9 years ago | 0

Answered
Loading multiple *mat files
For a basic explanation see the MATLAB documentation: <https://www.mathworks.com/help/matlab/matlab_prog/access-multiple-elem...

9 years ago | 1

| accepted

Load more