matlab

How to generate a guitar note

Back in a freshman or software programming class we had to write a program that would simulate the sound of a guitar pluck. I can make pure sin waves all day, but I am trying to remember how to do a sound like a guitar pluck. I remember it had something to with using random() and a falloff constant added to the sin wave, but I can not r...

Why is MATLAB reporting my variable uninitialized?

I made a class and in one of its methods I needed to calculate the distance between two points. So I wrote an ordinary function named "remoteness" to do this for me. Compilation Error: At compilation, "remoteness" was determined to be a variable and this variable is uninitialized. "remoteness" is also a function name and p...

How to determine whether a matrix is empty or not in matlab?

In my matlab program, I want to determine whether a variable or output of a function is empty or not, before going further. Actually, I've written a function which calculates an intersection point between two line segments. if there is no intersection, the function returns nothing (so the variable assigned by the function will be empty ...

Why does my MATLAB (R2008a) object's class change on a save/load cycle?

UPDATE: This is a known bug - link requires a login to Mathworks to access it. Summary of bug report An instance of a MATLAB user-defined class saved to a MAT file using Version 7.6 (R2008a) might not load properly if one of its property values is an instance of a different MATLAB class. Briefly, Mathworks reports tha...

How to apply moving windows to a 2D matrix in MATLAB?

Hi, I'm doing feature extraction from an image in Matlab. I'm having to apply many functions over nXn windows for this purpose (such as to find the variance over each 3X3 window, etc. Is there an easy and efficient way to do this in Matlab other than looping over the matrix and collecting the window elements each time? For some function...

What's the most efficient/elegant way to delete elements from a matrix in MATLAB?

I want to delete several specific values from a matrix (if they exist). It is highly probable that there are multiple copies of the values in the matrix. For example, consider an N-by-2 matrix intersections. If the pairs of values [a b] and [c d] exist as rows in that matrix, I want to delete them. Let's say I want to delete rows like ...

DAQ Triggers in Matlab

I'm writing a program that detects the speed of a object by hall effect sensors that are run into MATLAB through a DAQ (MCC USB-1408FS) The problem that has arisen is that I'm using a non-stop scan technique to detect the state of one of 3 sensors. Unfortunately this means that unless the object is rotating past each sensor at the exac...

Why is 24.0000 not equal to 24.0000 in Matlab?

I've written a program in which it is necessary to delete some points from a matrix if they exist. sometimes, there are more than one copy of them in the matrix. But the problem is that when it comes to check whether those points are in the matrix , matlab can't recognize them in the matrix although thery are exist. Let's begin from the...

In MATLAB, what ASCII characters are allowed to be in a function name?

I have a set of objects that I read information out of that contain information that ends up becoming a MATLAB m file. One piece of information ends up being a function name in MATLAB. I need to remove all of the not-allowed characters from that string before writing the M file out to the filesystem. Can someone tell me what character...

How do I combine setting axes limits and zooming in a MATLAB plot?

Here is the basic situation in a MATLAB session >> figure >> h=axes; >> y=sin(0:2*pi/100:pi); >> plot(y); >> set(h,'xlim',[20 80]); Now I want to be able to use the figure toolbar's Zoom In/Out buttons to reset the view so that the x-axes limits are the default, (ie [0 100]). However, they only allow one to zoom in and out of the curr...

How to determine whether V3 is between V1 and V2 when we go from V1 to V2 counterclockwise?

I have three vectors V1, V2, and V3. Their origin points are on the axes' origin. How could I determine whether V3 is between V1 and V2 when I move around counterclockwise from V1 to V2? It can't be done with obtaining their angles and evaluating these kind of conditions (pseudo-code): if angle(V3) > angle(V1) && angle(V3) < angle(V2...

Can we count MATLAB as programming language?

I wonder whether matlab could be considered as a programming language or not? ...

load values from textfile in matlab

I would like to load variabless from an textfile. e.g my text file varA varB varC In Matlab I would like to give these variables values so that every var is a 2x2 matrix so from the textfile containing the above information i would get an matrix that looks like this: [ 1 2 3 4 5 6; 1 2 3 4 5 6] Is this possible? added a second ex...

How to pass variable to a function created through the guide

I developed a form using with guide, i want to send a variable to that function through command line how it is possible if aanybody know s please tell to me thanks in advance ...

Multi-Dimension any()

I'm testing an arbitrarily-large, arbitrarily-dimensioned array of logicals, and I'd like to find out if any one or more of them are true. any() only works on a single dimension at a time, as does sum(). I know that I could test the number of dimensions and repeat any() until I get a single answer, but I'd like a quicker, and frankly, ...

Matlab object array method dispatching

In Matlab's new object model ('classdef', etc): If I have an array of the object, and I call an ordinary method, is the methods called for each object, or for the entire array, i.e. is a single object passed into the method, or the entire array? I know that in the old model, it got dispatched as the entire array. Thanks. ...

Why do I get a "Too many input arguments" error when not passing any?

I am working on some simple object-oriented code in MATLAB. I am trying to call one of my class methods with no input or output arguments in its definition. Function definition: function roll_dice Function call: obj.roll_dice; When this is executed, MATLAB says: ??? Error using ==> roll_dice Too many input arguments. Error in ==> ...

Matlab Fraction to Floating Point

After using the 'solve' function on an equation with one variable, it seems like Matlab doesn't like using floating point. So, my answer is ans = -2515439103678008769411809280/29019457930552314063110978530889-1/232155663444418512504887828247112*13479465975722384794797850090594238631144539220477565900842902305^(1/2) and I'm not sure wh...

nargin vs exist

Hi Given a function like: function foo(myParam) if nargin<1 myParam = 'default value'; end % if end % function I've seen people use something like the following in the place of the nargin version if ~exist('myParam', 'var') myParam = 'default value'; end %if I'm wondering if there is any preference either way? The "~exist..."...

Bilinear Transformation

Hi, This particular topic pertains to Digital Controls. I have a transfer function of my plant, which in this case is a servo motor, and it is in the z-domain. In order to determine the phase margin I need to look at the Bode plot, but first I have to use the bilinear transformation: z = (1+(T/2)*w) / (1-(T/2)*w); T-sampling rate, w = ...