Answered
How to find the area of a triangle given 3 vertices?
# Pick one vertex, let say V1, as "origin" # Get the two vectors of from this point to the other two points (V2-V1) and (V3-V1)...

8 years ago | 1

| accepted

Answered
How to add a row matrix to all other rows of a matrix?
Why not use simple concatenation? First transpose the row-vector into a m-by-1 column vector, of course: NewVarLasten = [Va...

8 years ago | 0

| accepted

Answered
How to gracefully terminate continiuous script?
Rik provided a nice solution. If you do not have a GUI you might be able to use my STOPLOOP function in your code (which creates...

8 years ago | 0

Answered
Find indices in cell array
A = {[-1 0 0 -1],1:4,[1 -1 1 -1 1 -1]} % example array fhFind = @(x) find(x == -1) ; IDX = cellfun(fhFind ,A,'un',0) ...

8 years ago | 0

Answered
Iterative plot, stop when lines intersect.
Comparing two numbers is always tricky. I suggest to use a tolerance, so instead of if x==y, ... use if (abs(x-y) <...

8 years ago | 0

| accepted

Answered
How do you find whether all the indices in a cell array contain a range of values? Outputs either 1 or 0 for each cell..
Define an anonymous function that does this for a numerical array CheckFcn = @(V,minV, maxV) all(V(:) > minV & V(:) < maxV)...

8 years ago | 0

Answered
how to run a while loop until esc is pressed?
I, the author of stoploop, suggest the function STOPLOOP: <https://uk.mathworks.com/matlabcentral/fileexchange/20455> ;)

8 years ago | 1

| accepted

Answered
list the result of the index values in ranges
A = [1 1 2 2 3 3 2 2 1 1]; X = arrayfun(@(k) find(A==k),1:3,'un',0) ; Y = cellfun(@(v) [v([true diff(v) > 1]) ; v([diff(...

8 years ago | 0

| accepted

Answered
Permutations Cycles Counting ... speed up
This is upto 10 times faster than your code (and indeed about 100 times faster than my previous code): [nR, nE] = size(p) ;...

8 years ago | 0

Answered
Permutations Cycles Counting ... speed up
Not vectorised, but less checking, not sure if it is faster nR = size(p,1) ; count2 = zeros(nR,1) ; tf = ~isnan(p) ; ...

8 years ago | 0

Answered
How can i obtain a signal like this? i have some problem with the code.
T = 1 ; n = 5/2 ; t = linspace(0,n*T,1000) ; x = sin(2*pi*t/T + pi) ; q = t < T/2 | t > T ; x(q) = 0 ; plot(...

8 years ago | 1

| accepted

Answered
Undefined function or variable
Did you add the folder holding these functions to your path (and saved it)?

8 years ago | 0

Answered
How do I take a table which has one value for every hour and produce an average for hours X:Y, one for each day?
Bin the times using HISTC and get the indices. Then accumalate the values using ACCUMARRAY. An example: % data : [time valu...

8 years ago | 0

Solved


Find all elements less than 0 or greater than 10 and replace them with NaN
Given an input vector x, find all elements of x less than 0 or greater than 10 and replace them with NaN. Example: Input ...

8 years ago

Solved


Column Removal
Remove the nth column from input matrix A and return the resulting matrix in output B. So if A = [1 2 3; 4 5 6]; and ...

8 years ago

Solved


Add two numbers
Given a and b, return the sum a+b in c.

8 years ago

Solved


Is this is a Tic Tac Toe X Win?
For the game of <https://en.wikipedia.org/wiki/Tic-tac-toe Tic Tac Toe> we will be storing the state of the game in a matrix M. ...

8 years ago

Solved


surrounded matrix
With a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones: A = [1 2 ...

8 years ago

Solved


Back to basics 21 - Matrix replicating
Covering some basic topics I haven't seen elsewhere on Cody. Given an input matrix, generate an output matrix that consists o...

8 years ago

Solved


How to subtract?
* Imagine you need to subtract one number from another using MATLAB. * You will not be using eval for this task. * Given two A...

8 years ago

Answered
How to adjust the ratio to compare the data in two variables?
You can transform your data linearly into, for instance, z-scores, to get a "normal" range of values. This does *not* change the...

8 years ago | 0

| accepted

Answered
How can I replace -9999 values by NaN throughout a 2-dimensional table
Read the file into a matrix M, and replace -9999 by NaNs using M(M==-9999) = NaN ;

8 years ago | 2

| accepted

Answered
count the last columns in matirix
Last10Columns = MyMatrix(:,end-9:end) or to be safe, if your Matrix has occasionally less then 10 columns: Last10Colum...

8 years ago | 0

Answered
How to get handles of a legend that was automatically generated?
H = findobj('type','legend') H.Location = 'best'

8 years ago | 5

| accepted

Answered
Create array with 7500 1s, 5000 2s, 8003s etc.
help repmat help cat help reshape help histogram

8 years ago | 0

Answered
Expanding Matrix with Integers (between decimal numbers)
Almost there, use the function interp1: T = [ 39.01; 41 ;43.13;45; 47.02] V = [19.47;9;11.84;13.35;11.70] ...

8 years ago | 1

Answered
Vectorised cell search and logical indexing
regex can work on a cell array of strings directly: block_new = {'abcd=x','abcd','a=xbc=x'} index4 = regexp('block_new',...

8 years ago | 0

Answered
How do I duplicate a row in a randomly ordered array?
A suggestion: [SF, TF, D] = ndgrid([1 2 3], [10 20 30 40], [180 360]) % combinations three spatial and four temporal freque...

8 years ago | 0

Answered
Adding noise to a sine wave
The expression "v.alpha" is interpreted by matlab as the contents of the _field_ "alpha" of the _structure_ variable "v". This...

8 years ago | 0

Load more