Questions tagged [matlab]

For mathematical questions about MATLAB; questions purely about the language, syntax, or runtime errors would likely be better received on Stack Overflow. MATLAB is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks.

MATLAB (Matrix Laboratory) is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks. MATLAB can be used when performing tasks such as signal processing and communications, image and video processing, computational finance, and computational biology. It is the foundation for a number of other tools, including Simulink and various toolboxes that extend its core capabilities.

In addition, MATLAB is a proprietary product of MathWorks. This means that, unlike other GNU GPL open source languages, both programmers and users must own a valid software license for running MATLAB code. There are several open source alternatives to MATLAB, in particular GNU Octave, which offers bidirectional syntactic compatibility with MATLAB, Scilab, SciPy, and Julia.

You could think about posting your question on Stack Overflow. They've got plenty of questions/answers already there.

Some informative links that show up quite often in answers:

User Amro has created a user-script for Matlab Syntax Highlighting for Stack Overflow. Use this link to install it.

3165 questions
1
vote
1 answer

Ensuring positive definite matrix defined by variables in Matlab

I am working with a piece of Matlab where I have: n = 4; Mbar = zeros(n,n); Mbar(1,1) = M; Mbar(2,2) = Ixx; Mbar(3,3) = Iyy; Mbar(4,4) = Izz; L = zeros(n,n); L = chol(Mbar)'; An error message said that it didn't like M, Ixx, Iyy, and Izz. So I…
Lanae
  • 355
1
vote
1 answer

Writing a MATLAB script that implements the trapezoidal formula

I am aware that there is a trapz function in MATLAB but I have been set the task of creating a script that implements the trapezoidal formula for numerical integration. Here is my attempt, unfortunately it is not working and help would be greatly…
Ryan
  • 11
1
vote
2 answers

Defining matrices in MATLAB

I'm completely new to MATLAB, and I can't figure out how to do the following: I have A=[-1,0.4,0.8;1,0,0;0,1,0]; b=[0;0.3;6]; What I want to do is define, for $N$ fixed but arbitrary, a $3\times N$ matrix C by having the $i$th column of C be…
Jeh
  • 414
1
vote
1 answer

Is there any significant meaning of the gradient of a matrix?

Is there any significant meaning of the gradient of a matrix? What does it imply? For example in Matlab: F = [ 2 4 5; 5 6 9; 0 1 3]; [Fx, Fy] = gradient(F); Fx = 2.0000 1.5000 1.0000 1.0000 2.0000 3.0000 1.0000 1.5000 2.0000 Fy…
1
vote
1 answer

Indexing a vector function, $E(s)=(E_1(s),E_2(s),E_3(s))$, in MATLAB without evaulating the function

This is simple, but for some reason I can't find the solution anywhere on the internet. I have a vector function in MATLAB $$E(s)=(E_1(s),E_2(s),E_3(s))$$ I want to be able to index it, so normally in MATLAB you would use 'E(1)', for element one.…
Freeman
  • 5,399
1
vote
1 answer

How to run this matlab code?

I got code that I can't run that is said to produce the result: z = [0:500:4000 5000:1000:12000]; data = [5050 4980 4930 4890 4870 4865 4860 4860 4865 ... 4875 4885 4905 4920 4935 4950 4970 4990]; fun = @(p)(4800 + p(1))*ones(size(z))…
1
vote
1 answer

Matlab error when using a vector

I keep getting an error when I run my code that uses a vector in my function. Here is my code: clear all; L=30; Nt=600; % Maximum # of time iterations. Nx=100; % Number of points in the x-direction …
1
vote
0 answers

Filtering integrated accelerometer data in MATLAB and later in Java (including drift correction)

Below an example of a velocity signal. It's a simple integration of accelerometer data with 100 measurements per second. As you can see there is drift (slowly drifting negative). I'm completely new to MATLAB so I dont really have a clue what to do.…
1
vote
1 answer

How to count the each number of row within a array in matlab

I have a matrix like- [1 2 3 3 3;1 2 2 5 5] From this matrix, I want to calculate in matlab that in each row how many numbers of 1 2 3 and 5? The result will be - 1 1 2; 1 2 2 I have tried with numberof1=sum(a(1:ac,:)==1); but this is valid if…
1
vote
1 answer

SPECGRAM return value

I was studying this code: fm = 8000; dt = 1/fm; % dt=0.000125 t = [1:dt:5]; y = sin(2*pi*200*t); tw = 0.05; ws = 2 .^ round( log2( tw*fm ) ); % ws=512 o = ws/2; % o=128 w = hanning(ws); [ X, f, tj ] = specgram( y, ws, fm, w, o ); What X…
JMFS
  • 247
1
vote
1 answer

Why do I keep getting a vertcat error in MATLAB?

For some reason the following code gives me the following error: Error using CI2 (line 94) Error using vertcat Dimensions of matrices being concatenated are not consistent. The code is: clear all % Odds Ratio for no clinically significant change,…
1
vote
2 answers

How could I randomly generate a random matrix with all eigenvalues inside the unit circle?

I want to generate a square matrix for which all eigenvalues lies inside the unit circle. Any simple way to do that in Matlab? I am not sure but such matrix is normally called schur-stable. P.S. I want eigenvalues to be allowed to be complex because…
Alex Mathy
  • 85
  • 5
1
vote
2 answers

Converting an integer to a vector of 0's and single 1

I have an array of labels in the form: [1;3;2;] I wish to convert this to an array of vectors, where only the i'th element is 1, and the rest are 0's. So the above would be (assuming 5 lables): [1 0 0 0 0] [0 0 1 0 0] [0 1 0 0 0] How can this be…
Trevor
  • 111
1
vote
0 answers

Using MATLAB to do spectral analysis for a periodic signal

As is said, I was asked to do spectral analysis for a periodic signal, i.e. plot the magnitude of its Fourier transform against frequencies. I know that for periodic signals, the spectral is just Fourier coefficients against integer multiple of its…
Xuxu
  • 1,174
1
vote
1 answer

Generate samples of sinusoid in matlab

I have to generate 100 samples of sinusoid in matlab with frequency 0.2Hz and sampling rate 2Hz. Until now i have pass into matlab the values: >> t=[0:99]; >> f=0.2; >> fs=2; The sin-wave function is this: $y(t)=A*sin(2pft+φ)$ Does the Amplitude…
20317
  • 139