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
3
votes
0 answers

Is there a way to configure MATLAB's plotchar function to other sizes?

plotchar plots a 35 element vector as a 5x7 grid. Is there a way to plot other grid sizes characteres?
3
votes
2 answers

How to write piecewise function using anonymous function in Matlab?

I would like to code the following function: $$f(x)=\begin{cases} \dfrac{\sin(x)}{x} & x\neq 0 \\ 1 & x = 0. \end{cases} $$ I am doing the following: f = @(x) (sin(x)./x.*(x~=0) + 1.*(x==0)); However, f(0)returns NaN, while it…
QFi
  • 1,215
3
votes
2 answers

In MATLAB, $\pi$ value is given as 355/113. why?

$\pi$ is an irrational number. MATLAB shows it equal to 355/113 in fractional format. Is there no better fractional representation than 355/113 within the limits of the finite precision the computers use? How is the value arrived at?
3
votes
1 answer

Algorithm for unique "additive" color mixing

my question is if i have only 3 basic colors (each made of rgb): color1 : R:150, B:zero, G:255 color2 : R:255, B:150, G:zero color3 : R:zero, B:255, G:150   They can be mixed using the formula : new_color = floor(X*0.9)+floor(Y*0.1) X and Y can be…
2
votes
4 answers

matlab get lower triangular matrix without loop and build in function

I tried to get the lower triangular n x n matrix without using any loop or build in function (except size()). is it even possible? I tried something like this: a(2:end,1) a(3:end,2) Unfortunately, this will work only with fix size matrix. any idea?
xiao li
  • 35
2
votes
0 answers

How do I compose a voronoi diagram?

I am trying to understand the algorithm of plotting a voronoi diagram. Here is a code I developed using whatever I could get off wikipedia. However the implementation is very slow and the complexity seems $n^2$. Is there a better approach? I am more…
Lord Loh.
  • 121
2
votes
1 answer

MATLAB: What is the simplest way to get an element of an matrix multiplication?

What is the simplest way to get an element of an matrix multiplication? Assume $A$ and $B$ are $n\times n$ matricies. And $1\le i\le n$ and $1\le j\le n$ are inidicies I tried $(A*B)(i,j)$ but this is no valid MATLAB syntax. Sure an other way is…
Matthias
  • 2,166
2
votes
1 answer

Adjacent faces to a vertex of a vertex of a polytope

I am a total newbie in Matlab. For a given faces of a polytope, how can I collect adjacent faces of a vertex of a polytope in matlab? Example: v = [ -1 0 0 %vertex 1 1 0 0 %vertex 2 1 1 0 %vertex 3 0 1 0 %... 0 0 1 1 0 1 1 1 1 1 1 1 ]; % faces are…
Getnet
  • 21
2
votes
0 answers

Error on integration

I'm trying to compute and plot the following integral: $$\int_0^\pi d\theta \int_0^{2\pi} \left( {\cos\theta \sin\theta(x-\sin\theta \cos\phi)\over (1+x^2-2x\sin\theta \cos\phi)^{\large\frac32}}\right)\ d\phi$$ the code I've written…
2
votes
2 answers

Matlab function to calculate

How can I input the two functions from this task in matlab ? A voltage peak in a circuit is caused by a current through a resistor. The energy E which is dissipated by the resistor is: Calculate E if This is my final solution: function E =…
2
votes
2 answers

I am trying to plot a function and its derivatives with matlab. Getting the error "inner matrix dimensions must agree"

I want to plot x(t)=t*exp(-3*t)+0.25*exp(-3*t), and its first and second time derivatives. I cannot even get the first plot correct. This is what I have done. t = [0:0.01:3]; x = t*exp(-3*t)+0.25*exp(-3*t); figure plot(t,x); From what I…
2
votes
1 answer

Defining piecewise constant function in matlab

Is there a simple way (or any inbuilt command) to define the following function in matlab: $f(a,b,x)=\sum\limits_{i=1}^n b(i)\chi_{[a(i),a(i+1))}(x), $ where $a(i)$ and $b(i)$ are the $i^{th}$ entries of vectors $a$ and $b$ of size $n+1$ and $n$…
Celestina
  • 1,146
2
votes
0 answers

MATLAB Tutorial for High School Student with Mediocre Math background

I am a High School Student who's looking for a MATLAB tutorial which doesn't assume any Math Background cause I just finished my Pre-Calculus and not really that comfortable with it. I do have a respectable experience with languages such as Python,…
kartlad
  • 181
2
votes
1 answer

Is there any matlab code to find out maximum eigenvalue of the randomly generated matrices?

I am running a matlab code for computing the Drazin inverse of the matrix $A$. Initial value of the iteration method is $X_0 = \beta A^{k}$, where $k = index (A)$(For $A\in \mathbb{C}^{n\times n}$, the smallest nonnegative integer $k$ such that…
Srijan
  • 12,518
  • 10
  • 73
  • 115
2
votes
1 answer

How to plot the graph for parameter vs x variable?

I'm trying to plot the graph for a parameter vs x variable. I used Matlab software. But I did not get a graph that I want. Is there anything wrong with my code? Here I attached the parameter value and Matlab code that I used. Hope someone can help…
1
2
3
22 23