# Questions tagged [matlab]

33759 questions

1

votes

0

answer

92

Views

### MATLAB 2-Layer Neural Network from Scratch

Currently, I'm working on a simple two Layer NN (25 input - sigmoid, 199 outputs - softmax) from scratch for debug reasons - Precisely, I want to track some values.
My input are batches or generally speaking matrices of dimension (rows x 25) in order to fit the input layer structure. Regarding my w...

1

votes

1

answer

97

Views

### does the matlab R2017a deploy neural network for c#(.net Assemly)

I use matlab R2017a but when i want to deploy my code to c#(.net assembly) it has a lot of error my code is very simple but i dont know why the matlab dont compile it in c#(.net assembly)
Below snapshots of error in compiling neural network.
does the c# visual studio run my code with this errors be...

1

votes

1

answer

121

Views

### How to get Fields from a MWStruct in C#

I am trying to conver a matlab code to DLL and using in this DLL into C#.
The Matlab Code give the out put in the form of Structure Array as
Output=
struct with fields:
Partion: [1×1 struct]
SWallR: [1×1 struct]
SWallL: [1×1 struct]
SWallB: [1×1 struct]
SWallF: [1×1 struct]
SWallC: [1×1 struc...

1

votes

2

answer

188

Views

### How do I fit distributions to data sets in matlab?

I'm trying to find a fit to my data using matlab but I'm having a lot of trouble, here's what ive done so far:
A = load('homicide_crime.txt') % A is a two column array the first column is the year and the second column is crime in that year
norm_crime = (A(:,2)-mean(A(:,2)))/std(A(:,2));
[f,x]=his...

1

votes

0

answer

46

Views

### Why can't matlab print eps with certain shapes?

I recently 'upgraded' from MATLAB R2011 to R2017b. Now when I try to print eps figures with relatively complex fill objects, they are rasterized.
This figure (and others like it) are OK:
This figure (and others like it) get rasterized (and larger, undesired margins):
The difference (from other examp...

1

votes

1

answer

57

Views

### How to fix Visual Tracker Benchmark error

I will be glad for any help to fix this
I have found a Benchmark dataset with ground truth data, in order to test Tracker algorithms, I had downloaded their source code, I followed the instructions in readme file :
I setup MATLAB engine for Python code
I had installed matplotlib python -m pip instal...

1

votes

0

answer

195

Views

### Evaluating a double integral in Matlab with Dirac Delta function

For an image processing project I need to calculate the following Integral in Matlab.
delta is the dirac delta function.
But the Problem is when I calculate some samples the output is always 0. My matlab code is as follows:
fun = @(x,y) dirac(0 - (x * cosd(135) + y * sind(135)));
q = integral2(fun,...

1

votes

0

answer

327

Views

### Matlab and Simulink simulation using set_param and get_param

I am using the command set_param and get_param to control a very simple simulink model, which only consists of a clock block and a scope. What I want is to let the simulink model run, get the real-tiem output of the clock block from Simulink to Matlab and stop the simulation when the clock value is...

1

votes

1

answer

58

Views

### Creating new rows in a matrix, where the elements of these rows have to be different from previous rows(same row cannot occur twice) Matlab

I'm trying to generate a 3x2 matrix. Each row is generated using randperm(3,2). This means each row is generated as a vector with 2 unique integers with values between 1 and 3.
The problem is that I want each new row to be different than all the previous. For example, if one row is [1 3] then no ot...

1

votes

1

answer

26

Views

### How do I pause execution in Matlab, but allow Copy\Paste via the keyboard

My question is similar to this:
Wait for gui to finish - matlab
But, the uiwait(f) doesn't work - when the user hits Ctrl-C it closes the app rather than doing a copy.
Here's the situation:
We're compiling MATLAB, and running WPF on top to provide the UI. However, we need to block the MATLAB executi...

1

votes

0

answer

232

Views

### Random Points in an n-Dimensional Hypersphere

This Matlab code,
creates a set of random points defined by Cartesian coordinates and
uniformly distributed over the interior of an n-dimensional
hypersphere of radius r with center at the origin.
the source is here.
clear all
clc
m = 20000;
n = 2;
r = 2;
%// generate circle boundary
C = [3 4]; %...

1

votes

1

answer

176

Views

### Implementing DCT from its connection to DFT via FFT in Matlab

I've got this assignment to implement a 1D DCT-II myself in Matlab where the 1D DCT-II of an even length sequence is defined as:
Naturally, using the built-in dct function is prohibited whilethe fft functions are available to me. Using the relation between DCT-II and DFT I've computed the DCT coeffi...

1

votes

0

answer

65

Views

### GARCH QML in matlab

I would like to calculate parameters for a GARCH using QML. I was wondering if the ARIMA toolbox from Matlab gives us the QML errors?
Greetings

1

votes

0

answer

343

Views

### Use cygwin as the mex compiler in matlab

I have set cygwin as the mex compiler for MATLAB 2016b by setting the environment variable MW_MINGW64_LOC to be G:\cygwin64. I then tested some simple examples. The g++ in cygwin works fine as a compiler. However, when I call the compiled mexw64 function, matlab crashes and the error message is as f...

1

votes

0

answer

75

Views

### C++ & Matlab: executable crashes when launched from Matlab (C++ allocation unsupported ?)

I'm developing a C++ project on Code::Blocks using the GNU GCC Compiler (on Windows).
The project is composed of 5 files and runs perfectly using Code::Blocks. However when I try to run the executable (found in the debug directory) from Matlab it crashes directly. From my point of view, it is becaus...

1

votes

1

answer

60

Views

### Matlab - Expand Figure Temporarily, Then Close

I'm expanding on the question asked at Expand (maximise) subplot figure temporarily — then collapse it back - I tried to post this as a comment to the original post, but I don't have sufficient privileges.
I was using the version in the comments:
function gcaExpandable
set(gca, 'ButtonDownFcn', [....

1

votes

0

answer

506

Views

### How to automatically find the threshold and sigma values for Canny Edge Detection?

I want to find the range of threshold values used and sigma values used for specific images. For example, If there is a set of images of different types such as too bright and high contrast, too bright and low contrast, not bright and high contrast, How can I know what range of threshold values and...

1

votes

0

answer

37

Views

### Running fast function and slow function with multi-threading in matlab

I'm new with multi-threading in Matlab so I guess that what I need to do will be simple for anyone with a little experience in it.
I have two functions f1 and f2 such that:
f1 - runs about 10 seconds and returns accurate results.
f2 - return estimated results immediately.
Both functions get the same...

1

votes

1

answer

270

Views

### How to automatically save the output image file in a specified folder?

I am using Canny edge detection on images. Since my original 10 images are in the path folder, C:\Users\X\Desktop\FoodRGB as 01.jpg, 02.jpg, 03.jpg and so on, I want to save all my output images in the folder C:\Users\X\Desktop\FoodCanny as 01.jpg, 02.jpg, 03.jpg.
I figured that I have to use imwrit...

1

votes

1

answer

65

Views

### Matlab: Error using gammaln… while plotting psychometric functions

I'm using the toolbox psignifit to plot psychometric functions from a dataset. My code looks essentially like the following:
load data.mat
options = struct;
options.sigmoidname = 'logistic';
result = psignifit(data,options); % this is where the error occurs
result.Fit
result.conf_Intervals
plotPsy...

1

votes

1

answer

79

Views

### How to create a program in Matlab to compute the Hii of the Hat matrix

Can anyone help me on how to compute the Hii matrix
It is supposed to get a single values.
However, in my code, it is appeared as 2x2 matrix.
This is my code in Matlab:
faithfuldat = xlsread('faithful.csv');
save faithful.mat faithfuldat % command form
[N,dim]=size(faithfuldat);
fData = fait...

1

votes

0

answer

325

Views

### Matlab connection error warning

Every time I start Matlab I am shown a modal Warning message to alert me to the fact that Matlab couldn't connect to MathWorks. I am searching for a way to stop Matlab from attempting this connection, or at least to disable the message. I work on an offline system, which has no internet access.
I co...

1

votes

0

answer

59

Views

### how to implementation Center Location Error (CLE) code

I'm trying to write the which corresponds to this formula, which one is correct I'm grad for any help
I load the groundtruth variables and the results too they are in a txt file in this form [x,y,w,h] = 100,22,12,32
filename_groundtruth = 'D:\data_seq\david2\anno\groundtruth_rect.txt';
[groundtruth...

1

votes

0

answer

36

Views

### Elastic line equation in Matlab - Error using Mupadengine/feval - Error in dsolve>mupadDsolve - Error in dsolve

I can't understand the solution of multiple differential equations in Matlab. In this example, I'm trying to work with independent equations: the program should solve them separately (and it does, see below) and together (it doesn't!), shouldn't it?
N.B. The equations describe the elastic line accor...

1

votes

0

answer

93

Views

### Ordered Isoline Calculation from 3D Triangular Surface in MATLAB

I need to extract the isoline coordinates of a 4D variable from a 3D surface defined using a triangulated mesh in MATLAB. I need the isoline coordinates to be a ordered in such a manner that if they were followed in order they would trace the path i.e. the order of the points a 3D printer would foll...

1

votes

1

answer

229

Views

### Plotting spheres around given coordinates in 3D in Matlab

I am working on model of an object sliding on some rough surface consisting of spheres with a small random variance in position. In the graphics I want the spheres to be of a given radius, however when using scatter3 this wont work, the sizes of the circles change when I zoom in or out. I could easi...

1

votes

1

answer

80

Views

### How to assign a matrix to a cell of a cell array

I'm working on matlab and try to assign a matrix to one cell of a cell array. However, there was always something wrong. Here is the code:
C = {};
myMatrix = xlsread('myexcelfile');
C{'ID', 'info'} = myMatrix;
Then matlab prompted that
'Expected one output from a curly brace or dot indexing express...

1

votes

2

answer

20

Views

### Issue with plotting in MATLAB (using ode45)

Alright so i want to plot the right side as a function of N using this equation:
dN/dt=-0.5N+100
I'm using MATLAB and my problem is that the plot stops at an x value of 200.
I'm using the following code:
T = 1000;
eq = @(t,N)(-0.5*N+100);
[t,N] = ode45(eq,[0 500],-5);
plot(N,-0.5*N+100)
axis([0 100...

1

votes

1

answer

328

Views

### Hierarchical Clustering in MATLAB

I have clustered my data X with hierarchical clustering in the following way:
X = [1 1 1;
2 2 2;
1 1 0;
1 2 2];
Y = pdist(X);
T = linkage(Y, 'complete');
c = cluster(T,'maxclust',2);
So, X(1,:) and X(3,:) belongs to cluster #1 and others belongs to
cluster #2.
How can I determine to which cluster a...

1

votes

1

answer

34

Views

### Optimize the code by omitting an unnecessary loop

I want to optimize some examples by omitting an unnecessary loop but I don't know how. Here are the examples:
%Subtract 7 from all elements on the matrix diagonal
A=rand(100,100)*10;
for i=1:100
A(i,i)=A(i,i)-7;
end
---
%Count the number of elements of matrix A which are bigger than the adequate ele...

1

votes

0

answer

56

Views

### Calculate nolinear model of vibration control

I am studding automatic and have a matlab/SIMULINK model of nonlinear vibration. I am trying to resolve the same problem using python instead.
Here we have a schema. The black frame is a part that I have already. I also have a Model tłumnika MR (eng. Magnetorheological Damper). Just I don't know ho...

1

votes

1

answer

100

Views

### train the network with matlab matconvnet

I want to train my network using matlab and matconvnet-1.0-beta25.
My problem is regression and I use pdist as loss function to get mse.
The inputs data is 56*56*64*6000 and the targets data is 56*56*64*6000 and network architecture is as follows:
opts.networkType = 'simplenn' ;
opts = vl_argparse(o...

1

votes

1

answer

34

Views

### Previous business day in different time zone - Matlab

I want to obtain the previous business day in Europe (country: Netherlands).
I know that you can use the following function to obtain the previous business day in the US:
dy = busdate(floor(now), -1);
However, how do you add the locality into account?
A good example is 01/15/2018. The US market was...

1

votes

0

answer

244

Views

### how to project a low pca dimension point back to original pca space in matlab

I have a 455 samples by 30 features matrix X. I am using the following pca projection into 2D:
[coeff, score, ~, ~, ~, mu]=pca(X');
gscatter(score(:,1),score(:,2),Y,'br','.');
Where Y are lables of the 455 samples.
Assuming I have a set of new 2D points z n samples by 2, which I want to project bac...

1

votes

0

answer

54

Views

### Most efficient way to track multiple small objects in MATLAB?

I am relatively new to image processing, and have never attempted to do anything with images in MATLAB, so forgive me if i am making some very rookie errors.
I am attempting to make a program that will track ants in a video. The video is taken from a stationary camera, and records the ants from a bi...

1

votes

0

answer

486

Views

### How to compare different facial images on Matlab without using data set?

I am working on a Matlab facial recognition project.
What I have to do is to read two different images of same person side by side and extract their local features (like eyes, nose and mouth).
My code reads images and detects features, I need a function for comparing any two face images and tell i...

1

votes

1

answer

76

Views

### Fitting polynomials with degree>2 using fminunc

I am trying to find the coefficients for polynomials of degree n using fminunc. I know polyfit but I have to use fminunc (or lsqnonlin) because I need to extend my model at a later point. Anyway, my objective function is simply the nonlinear least-square problem and I applied the same centering and...

1

votes

1

answer

474

Views

### write a compound array to h5 in Matlab?

I need to write a struct array like following to h5? How to do this? Thanks a lot!
wdata.serial_no = int32(5);
wdata.temperature = 6.0;
wdata.pressure = 7.0;
wdata_array{1} = wdata;
wdata_array{2} = wdata;
My trial：
% construct the struct array
wdata.serial_no = int32(5);
wdata.temperature...

1

votes

2

answer

164

Views

### MATLAB - lsim() function not giving proper attenuation for my RC transfer function

I am trying to model a RC filter's transfer function in order to know how an input signal is deformed when it reaches my sample. I first build the RC filter's transfer function to fit my experimental data but when I give an input signal to the lsim() function, it doesn't give me proper results, eve...

1

votes

0

answer

384

Views

### Matlab error: constructor must preserve the class

connected question: Returning an object of a second class through the constructor of first class but the answer doesn't seem to be of much help for me.
I'm having trouble with Matlab constructors. I want to create a class A and a subclass B, such that I can provide the constructor of B with either t...