Answered
Multidimensional array indexing question
Your understanding is correct: if a logical index is shorter than the array it is being used on, then the index is not expanded ...

10 years ago | 0

| accepted

Answered
Replacing elements of a matrix with vectors
Simply put the replacement arrays inside a cell array and then use the starting matrix as indices: >> mat = [1,2;3,4]; >...

10 years ago | 1

| accepted

Answered
How to check if any row has 0?
>> idx = any(A==0,2) % logical index idx = 1 0 0 1 >> find(idx) % subscript index ans...

10 years ago | 1

| accepted

Answered
How to plot two n*n matrices in same plot?
You start by reading the <http://www.mathworks.com/help/matlab/ref/plot.html |plot|> documentation, which tells you that if both...

10 years ago | 0

| accepted

Answered
How to replace the matching cell
This might do what you want: inp = {... 'pass','OK','Out','OK','OK','Out';... 'pass','OK','Out','OK','OK','Out';... ...

10 years ago | 0

| accepted

Answered
Read multiple txt files using a loop
Your mistake was to create lots of individual numbered variables for the date strings. This is a very bad idea, because it makes...

10 years ago | 0

| accepted

Answered
creating multi-line title with variable values
You can also make a multiline <http://www.mathworks.com/help/matlab/ref/title.html |title|> by constructing a string with newlin...

10 years ago | 0

| accepted

Answered
From 2 given values find the range from a vector
D = [110,140,160,225,280,315,355,400,450,500] Dmin = 112; Dmax = 356; idx = Dmin<=D & [true,D(1:end-1)<=Dmax]; out...

10 years ago | 0

Answered
Find rows with maximum number and replace them with 1
A = [5;0;0;4;3;0]; [cnt,idx] = histc(A,unique(A)); [~,idz] = max(cnt); B = idx==idz; outputs this >> B B = ...

10 years ago | 1

| accepted

Answered
please help me in sort row
x = [0,0,0,0,0,40,40,-40,-40,-40,-40,-40,-40,80,80,80,80,80,80]; [uni,idu] = unique(x); [cnt,idx] = hist(x,uni); [~,i...

10 years ago | 0

| accepted

Answered
Removing duplicate strings from an array and original
You can use much the same method as in my answer to <https://www.mathworks.com/matlabcentral/answers/298533-remove-duplicates-an...

10 years ago | 0

| accepted

Answered
Remove duplicates and original also
Assuming that the vector |A| is sorted: >> A = [1,2,2,2,3,3,3,4,5]; >> B = unique(A); >> B(histc(A,B)<2) ans = ...

10 years ago | 0

| accepted

Answered
how to get sum of numbers appearing in triangle in a matrix
The simplest solution is the best: >> f = [1 2 3 4; 5 6 7 8; 2 3 4 5] f = 1 2 3 4 5 6 ...

10 years ago | 2

Answered
Is there an easy way to plot many different arrays of varying sizes without manually specifying each one
To create one plot with multiple lines, you should join all of the data into one array, padded with NaN's to make them all of th...

10 years ago | 0

Answered
Stay in the loop without changing counter until condition met
MATLAB is most effective when you learn to use arrays to hold your data, so this task becomes quite simple when we store those v...

10 years ago | 0

Answered
I want to sort a data like this as given below
This code locates the beginning and end values of any non-zero sequence, and calculates their differences: >> X = [0,0,3,4,...

10 years ago | 1

| accepted

Answered
Should I remap keyboard shortcuts?
_"if there will be any negative consequences"_ None. MATLAB provides the option to change the shortcuts: <http://www.ma...

10 years ago | 0

| accepted

Answered
What other command can I use instead of isempty?
You don't have to _"guess"_ how MATLAB works: the helpful workers at TMW spent many thousands of hours writing documentation tha...

10 years ago | 2

Answered
Assign parameters to an array of zeros, ones, twos and threes
Just use |1+Z| (from my answer to your last question) as indices: Z = [... 0 1 1 1 1 1 1 ...

10 years ago | 0

| accepted

Answered
How to create logical binary matrix where two variables are from the same row ?
You could use <http://www.mathworks.com/help/matlab/ref/unique.html |unique|> and <http://www.mathworks.com/help/matlab/ref/sub2...

10 years ago | 0

| accepted

Answered
Pre-specify user input to function
You could use a <http://www.mathworks.com/help/matlab/ref/persistent.html persistent variable>: function c = myfunc(a,b) ...

10 years ago | 0

| accepted

Answered
how to solve this error 'Error using horzcat Dimensions of matrices being concatenated are not consistent.'
Taking a wild guess: [value,ind] = max(MutualInfo(b.',a.')); or [value,ind] = max(MutualInfo(b,a)); But really w...

10 years ago | 0

Answered
flip elements of a row vector
a = [1 2 3] fliplr(a) or a(end:-1:1)

10 years ago | 0

| accepted

Answered
In a cell how do I extract a specific range of values from a few columns that have a certain value in another column?
This method will correctly preserve the order of the input data: C = {... 'Bob',1,100; 'Bob',3,200; 'Bob',4,500; ...

10 years ago | 1

| accepted

Answered
Plotting Graphs in Matlab
MATLAB is simply plotting it exactly what you are telling it to. You are getting confused about calculating vs plotting data, an...

10 years ago | 0

Answered
How can I find the sum of the perimeter of a matrix?
In one line is easy and very fast: >> M = [1,2,3;1,2,3;1,2,3]; >> sum(sum([M([1,end],2:end-1),M(1:end,[1,end]).'])) a...

10 years ago | 2

Answered
Embedding a while into a for loop
You are turning something simple into something complicated. Just one loop is required: dna = 'ATCCCGGCG'; p = 'CG'; ...

10 years ago | 0

| accepted

Answered
how to find maximum and minimum in a matrix
The simplest way would be to use <http://blogs.mathworks.com/steve/2008/01/28/logical-indexing/ logical indexing>: >> idx = ...

10 years ago | 1

Answered
weird matrix multiplication with or without bracket
_"Theoretically, adding a bracket will not change result"_ Actually the two calculations are not equivalent, there is no reas...

10 years ago | 1

Answered
How to get ascii value of characters stored in an array?
MATLAB makes this really easy: you can use the double function: >> str = 'Hello World'; >> double(str) ans = 72 101 ...

10 years ago | 4

Load more