matlab

MATLAB: Find all NaN elements inside an Array

Is there a command in MATLAB that allows me to find all NaN (Not-a-Number) elements inside an array? ...

Generate Square Mesh, Given an Unordered X, Y and Z Vectors

I have three arrays of the same length in Matlab, X, Y and Z. X(i), Y(i) and Z(i) forms a pair of 3D coordinates. The issue now is, how to use these three arrays to generate square meshes, as shown below: I got the image from mesh plot in Matlab documentation. So obviously mesh command is not what I want because it plots the meshes it...

Why won't this axes object display correctly in MATLAB?

I am writing two small psychoacoustic testing applications in MATLAB. The first one works without problems but the second one doesn't, and I just can't figure out why. Here is the problem: the axes object is created, but it is empty. Here is the code that creates this figure and axes: hFig = figure('dockcontrols','off','menubar','no...

Stopwatch function in R

Is there an R timer or stopwatch function similar to MATLAB's tic/toc? ...

Fill the holes in OpenCV

I have an edge map extracted from edge detection module in OpenCV (canny edge detection). What I want to do is to fill the holes in the edge map. I am using C++, and OpenCV libraries. In OpenCV there is a cvFloodFill() function, and it will fill the holes with a seed (with one of the location to start flooding). However, I am trying to...

Plotting 4 curves in a single plot, with 3 y-axes

I have 4 sets of values: y1, y2, y3, y4 and one set x. The y values are of different ranges, and I need to plot them as separate curves with separate sets of values on the y-axis. To put it simple, I need 3 y-axes with different values (scales) for plotting on the same figure. Any help appreciated, or tips on where to look. ...

Simple problems with MATLAB

I have three questions: 1) I want to compute the following using MATLAB: 11^2 + 13^2 + 15^2 + ... + 109^2 + 111^2 I have tried using: x = [11^2 13^2 15^2 ... 109^2 111^2] z = cum(single(x)) but I got an error... 2) I want to display '2 sin/pix'... I tried: tittle('2 sin/pix') Can I represent the display without displaying it...

What is the equivalent of MATLAB's repmat in NumPy

I found repmat([1;1], [1 1 1]) in MATLAB code. I am trying to find a NumPy command to do the same thing, but I found that can't use with 3d [1 1 1] ? ...

MATLAB: sum of matrix elements

Given the matrix: A=[1 2 3; 4 5 6; 7 8 9] how would you use the for loop to compute the sum of the elements in matrix? write a one line MATLAB command using the function sum() to sum the matrix elements in A My answer: 1) for j=1:3, for i=j:3, A(i,:) = A(i,:)+A(j+1,:)+A(j+2,:) end end 2) sum(A) Is that the c...

Loops in MATLAB

How many times will the following loop execute? x=-4 while x <8 x=x+3 end Can anyone explain it to me? ...

Just curious about result from NumPy function!

I have used NumPy for my Master thesis. I've converted parts of the code from MATLAB code, but I have doubts in NumPy/Python when I reference: m = numpy.ones((10,2)) m[:,0] which returns: array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) and when I ref to: m[:,0:1] it returns: array([[ 1.], [ 1.], [ 1.], ...

MATLAB: Getting an array of cells from MATLAB to Java

I have an array created in MATLAB that contains a number of cell type objects which contain arrays of doubles. It's basically a <1xn cell> array and each cell is an array of doubles. What I want to do is to somehow export these so that I can then insert the data into Java as a ragged array of arrays of type int. Any thought on how to b...

How to randomly select from a list of 47 names that are entered from a data file?

I have managed to input a number data file into a matrix but have been unable to do so for any data that is not a number. I have a list of 47 names and supposed to generate a random name from the list. I have tried to use the function textscan but was not going anywhere. Also how do I generate a random name from the list? All I have be...

MATLAB and function

I want to calculate the function y(t) from the equation: y(t) = -3t^2+5, t>=0 y(t) = 3t^2+5, t<0 for -9 <= t <= with the step-size 0.5 and I want to plot it by using MATLAB. I approach this question in two ways: First t=0:0.5:9 y=-3*t^2+5 t1=-0.00000000001:0.5:-9 y1=3*t^2+5 plot(t,y,t1,y1) Second by using loop t=-9:0.5:9 if(t...

matlab deals with Fibbonacci

The Fibonacci series is given as follow: 1, 2, 3, 5, 8, 13, 21, ... How can I write a script file to calculate and print out the n-th Fibonacci term for n>2, where n is input by the user. This is what I've tried: n=input('n: '); while(n < 3) disp('must enter number >= 3') if(n < 3) fprintf('\n\n P...

Divide two polynomials using MATLAB

I want to divide p(x) by q(x) given that: p(x)=-5x^4+3x^2-6x q(x)=x^2+1 I tried: p=inline('-5*(x^4)+3*(x^2)','x') p = Inline function: p(x) = -5*(x^4)+3*(x^2) q=inline('x^2+1','x') q = Inline function: q(x) = x^2+1 deconv(p,q) but got error: ??? Undefined function or method 'filter' for input arguments of t...

preventing data from being freed when vector goes out of scope

Is there a way to transfer ownership of the data contained in a std::vector (pointed to by, say T*data) into another construct, preventing having "data" become a dangling pointer after the vector goes out of scope? EDIT: I DON'T WANT TO COPY THE DATA (which would be an easy but ineffective solution). Specifically, I'd like to have some...

Difference between MATLAB's matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = // Why do you get a matrix? 0.3820 0 0 2.6180 #2 K>> p,d=eig(A) // Not sure ...

MATLAB Solving equations problem

I want to solve these equations using MATLAB and I am sure there is a non zero solution. The equations are: 0.7071*x + 0.7071*z = x -0.5*x + 0.7071*y + 0.5*z = y -0.5*x - 0.7071*y + 0.5*z = z I wrote in MATLAB: [x,y,z]=solve('0.7071 * x+0.7071 * z=x','-0.5 * x+0.7071 * y+0.5 * z=y','-0.5 * x-0.7071 * y+0.5 * z=z...

How to efficiently find correlation and discard points outside 3-sigma range in MATLAB?

I have a data file m.txt that looks something like this (with a lot more points): 286.842995 3.444398 3.707202 338.227797 3.597597 283.740414 3.514729 3.512116 3.744235 3.365461 3.384880 Some of the values (like 338.227797) are very different from the values I generally expect (smaller numbers). So, I am thinking that I will remove...