matlab

Calling matlab callback/function handle from Java

How do I pass a matlab function handle to a Java object and invoke it from within Java (that is, I want Java to tell matlab when it is ready with a calculation). I am trying to use the com.mathworks.jmi.Matlab class for evaluating Matlab expressions in the Java object, but I can't see how to 1) transfer the callback funcktion handle to J...

Getting matlab timer to update matlab GUIDE gui?

I have a matlab timer object. It is updating a global variable FOO once per second. I have a matlab GUIDE GUI, with a couple of controls, and a single plot frame. The plot frame gets updated by some of the GUI controls, and it gets updated by the timer object. Basically, there are two global variable FOO and BAR. The timer updates F...

mrdivide function in Matlab- what is it doing and how to do it in Python?

I have this line of code: a/b I am using these inputs: a=[1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9] b=ones(25,18) this is the result: [5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], a 1x25 matrix. what is matlab doing? I am trying to duplicate this behavior in Python, and the mrdivide documentation in matlab was unhelpful. where d...

MATLAB: calling GUI/GUIDE functions from outside

When I try to invoke a subfunction in a GUI/GUIDE file (using a function handle which has been exposed as a global variable), a new axes is always created even if I set the axes to a specific axes in the GUIDE figure. Does anyone know why this is happening? GUIDE code is: ############################################################### f...

Displaying information from MATLAB without a line feed

Is there any way to output/display information from a MATLAB program without an ending line feed? My MATLAB program outputs a number a bit now and then. Between outputting the number the program does a lot of other stuff. This is a construct mainly to indicate some kind of progress and it would be nice not to have a line feed each time,...

How do you create a matrix from a text file in MATLAB?

I have a text file which has 4 columns, each column having 65536 data points. Every element in the row is separated by a comma. For example: X,Y,Z,AU 4010.0,3210.0,-440.0,0.0 4010.0,3210.0,-420.0,0.0 etc. So, I have 65536 rows, each row having 4 data values as shown above. I want to convert it into a matrix. I tried importing data fro...

Calculating Hamming weight efficiently in matlab

Given a MATLAB uint32 to be interpreted as a bit string, what is an efficient and concise way of counting how many nonzero bits are in the string? I have a working, naive approach which loops over the bits, but that's too slow for my needs. (A C++ implementation using std::bitset count() runs almost instantly). I've found a pretty n...

How do I convert a MATLAB image processing program to java?

I've written an image processing program in MATLAB which makes heavy use of the MATLAB Image Processing Toolbox, especially the morphological operations (imopen, imclose) as well as imadjust. We do a lot of spline fit operations and medfilt2 and medfilt1 a lot also. We have a client who wants us to convert this program to Java. I would...

Regex, csv-type layout, allow for "" inside quoted strings?

I need a regex that will parse a csv-style file, something like 57 fields wide, most fields enclosed in quotes (but maybe not all), separated by commas, with quoted fields having the possibility of embedded doubles ("") that represent single quotes in the evaluated string. I'm a regex beginner/intermediate, and I think I can get pretty ...

Vector to Matrix syntax in MATLAB...

Is there a way to combine 2 vectors in MATLAB such that: mat = zeros(length(C),length(S)); for j=1:length(C) mat(j,:)=C(j)*S; end Using normal MATLAB syntax similar to: mat = C * S(1:length(S)) This gives a "Inner matrix dimensions must agree error" because it's trying to do normal matrix operations. This is not a standard Lin...

Segmentation fault operating a camera with MATLAB

I am using Matlab to operate a camera. It is an IDT SharpVision camera, and I am using the Matlab interface provided by the company. When I try to acquire an image, I get a segmentation fault. I have tried preallocating memory by creating an empty array for the image, but this does not work. This is the line of code that causes the...

How to represent a polygon with hole(s) ?

It's usually popular to work with polygons with their vertices sorted CW or CCW in vectors(2*1 or 1*2 matrices). However, how to state polygons with holes in vectors? I'm going to apply various process on these polygons, so I want a way of representing with which I could work easily or efficiently.(i.e how to state that kind of polygon...

MATLAB - floor question

I'm a MATLAB beginner. Here's the problem: >> a = floor(7/2.5) a = 2.00 >> b = rem(7,2.5) b = 2.00 >> c = floor(b/2) c = 0 c should be 1, right? Why is it 0??? It is different when b = 2 is entered directly as follows: >> b = 2 b = 2.00 >> c = floor(b/2) c = 1.00 ...

MATLAB - add a plot to a hist

I'd like to represent on a distribution the plot that fit to it. I can't find how to do it (I'm a MATLAB beginner). Thanks for any help! ...

Using Python to replace MATLAB: how to import data?

I want to use some Python libraries to replace MATLAB. I'd like to know how could I import excel data in Python (for example using numpy) to use them. I don't know if Python is a credible alternative to MATLAB, but I want to try it. If you have any tutorial I'd be glad to read it! Thanks a lot! ...

How to add image in MATLAB GUI?

I want to switch back and forth between two images, like blinking: 1 second for the first image and one second for second image. ...

How to normalize a vector in MATLAB efficiently? Any related built-in function ?

I normalize a vector V in MATLAB as following: normalized_V = V/norm(V); however, is it the most elegant (efficient) way to normalize a vector in MATLAB? ...

Removing Similar Elements in Matrix

I'm trying to figure out how to remove an element of a matrix in MATLAB if it differs from any of the other elements by 0.01. I'm supposed to be using all of the unique elements of the matrix as thresholding values for a ROC curve that I'm creating but I need a way to remove values when they are within 0.01 of each other (since we are as...

find length of sequences of identical values in a numpy array

In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: d[t] is the distance at time t (and the timespan of my data is len(d) time units). The events I'm interested in are when the distance is below a certain threshold, and I want to compute the duration of these even...

How to get MATLAB to recognise newly added static methods?

I am using classes and static methods to 'scope' functions in a namespace, similar to C#. However, every time I add a new method to a class, at first it is not found. I have to restart the MATLAB environment (2007a) for the new methods to be recognised. Surely there is an 'update' or 'refresh' type command that I can use so that I do no...