MATLAB ProgrammingSponsored by Jamf Now

383

Solutions

455

Contributors

MATLAB is a numerical computing environment and proprietary fourth-generation programming language. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, Fortran and Python. Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing capabilities. An additional package, Simulink, adds graphical multi-domain simulation and model-based design for dynamic and embedded systems.

Share tech news, updates, or what's on your mind.

Sign up to Post

I cannot print to the command window when the Matlab Instance is launched with "matlabinit()".

I've tried (within the *.m file executed via MLEvalString()):
disp('show something');
fprintf('show something');

When I launch Matlab independently, "disp()" and "fprintf()" work just fine.

Any ideas?

Thanks in advance for your help.
0
Cloud Class® Course: Python 3 Fundamentals
LVL 12
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Hi to all,

I use findpeaks function in my code to calculate the four maximum values of a fft function.

I use it in this way:

[maxpeaks, idx] = findpeaks(10*log10(psdx),'MinPeakDistance',195,'NPeaks',4,'MinPeakHeight', -Inf, 'SortStr','descend')

Open in new window


The problem is that I need to run the code in a Matlab version which doesn't have the Signal Processing Toolbox. Is there any solution to write a similar function without the need of the SP Toolbox?

Thank you!
0
Dear experts,

I am a chartered accountant, CIMA and CFA.

I have a lot of experience in writing excel formulae (the entire credit goes to this forum, thank you experts).

I now want to pursue Financial Engineering.

I am learning C, C++ now. Once I become well versed with these two languages, I will move to learning Python.

Now from robustness, depth and FE requirement is Python better or MATLAB

I am not sure I have the bandwidth to complete/learn both.

Till date I have been learning C and I did not struggle to pick up the synatax or logic.

Kindly advice.
0
Please help i want the image to be in canny edge n perform fuzzy logic with this code

img1=imread('F:\Matlab Project\7 sem\currency\10.jpg')




Igray = 0.2989*img4(:,:,1)+0.5870*img4(:,:,2)+0.1140*img4(:,:,3);
%Igray1=edge(Igray,'Canny');
%figure
%image(Igray,'CDataMapping','scaled');
%colormap('gray')
%title('Input Image in Grayscale')

%Convert Image to Double-Precision Data
I = double(Igray);


%Scaling the factor
classType = class(Igray);
scalingFactor = double(intmax(classType));
I = I/scalingFactor;

%Obtain the Image Gradient

Gx = [-1 1];
Gy = Gx';
Ix = conv2(I,Gx,'same');
Iy = conv2(I,Gy,'same');

%figure
%image(Ix,'CDataMapping','scaled')
%colormap('gray')
%title('Ix')

%figure
%image(Iy,'CDataMapping','scaled')
%colormap('gray')
%title('Iy')

%Define the Fuzzy Inferences System
edgeFIS = newfis('edgeDetection');

%Specify the image gradients, Ix and Iy, as the inputs of edgeFIS
edgeFIS = addvar(edgeFIS,'input','Ix',[-1 1]);
edgeFIS = addvar(edgeFIS,'input','Iy',[-1 1]);

%
sx = 0.1;
sy = 0.1;
edgeFIS = addmf(edgeFIS,'input',1,'zero','gaussmf',[sx 0]);
edgeFIS = addmf(edgeFIS,'input',2,'zero','gaussmf',[sy 0]);
%
edgeFIS = addvar(edgeFIS,'output','Iout',[0 1]);

%Specify the triangular membership functions, white and black, for Iout.
wa = 0.1;
wb = 1;
wc = 1;
ba = 0;
bb = 0;
bc = 0.7;
edgeFIS = addmf(edgeFIS,'output',1,'white','trimf',[wa wb wc]);
edgeFIS = addmf(edgeFIS,'output',1,'black','trimf',[ba …
0
I need to wrap a Fortran program to run from Matlab.  Has anyone done this before?  I did not find much information in my search.  Thank you for any help you can give.
0
Calculating Beta values using for weibull analysis using matlab or excel.

I tried to follow a string from 2012 but i was unable.

I understand how to plot this graph on paper to find the 63rd percentile but it is the beta part that i am having trouble with..

any help would be much appreciated!
0
I have an array (raw_acceleration) of 1600 elements acquired every 10 seconds at 160Hz from a sensor.
i use this array to calculate the fft and the Power Spectral Density and it works very well:


Fs=160;
raw_acceleration = u;
N = length(raw_acceleration);
xdft = fft(raw_acceleration);
xdft = xdft(1:floor(N/2+1));
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(raw_acceleration):Fs/2;

plot(freq,10*log10(psdx))
grid on
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')

Open in new window


I obtain this plot:
psd-sand.png
As you can see, I obtain four peaks centered around four different frequencies.

I would like to have a Matlab code which is able to automatically find these four maximum peaks and their frequency.
At the moment, I always need to plot the graph and manually detect the maximum peak and its frequency.

Is there any way to do this by code?
I hope you an help me.

This is a sample of raw_acceleration array:

raw_acceleration= 
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0003
    0.0003
    0.0003
    0.0003
    0.0003
    0.0003
    0.0003
    0.0003
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0021
    0.0038
    0.0038
    0.0038
    0.0038
    0.0038
    0.0038
    0.0038
    0.0038
   -0.0002
   -0.0002
   -0.0002
   -0.0002
   -0.0002
   -0.0002
   -0.0002
   -0.0002
    0.0048
    0.0048
    0.0048
    

Open in new window

0
I have a set of seven parameters which are numerical values (i.e. current readings, pitch, roll and yaw angles, acceleration, etc..) and I use them to classify a vehicle behavior.
For example, if:

current=5A
pitch=12 degrees
yaw=41 degrees
Y_acc = 10 m/s^2
...

then the vehicle behaviour is classified as A otherwise if

current=7A
pitch=15 degrees
yaw=42 degrees
Y_acc = 11 m/s^2
...

then the vehicle is classified as B, and so on..

What is the best way to implement this kind of classification in Matlab?
Should I use a simple neural network? Or a classification method like SVM?
Is there any tutorial or example?

I have a set of data where each set of parameters is related to a specific behavior, so I can use this to train my model.

Thank you!
0
hi to all,

I have a vector in Matlab which contains samples acquired at 10Hz from an accelerometer mounted on a frame's vehicle.
This vector contains the acceleration values along the Z-axis.
The acquisition time is 103 seconds.

I would like to plot the frequency values in Hz since I'm trying to study the terrain frequency response.

I tried to use the fft function available in Matlab, but I do not know how to proceed.
Can you help me, please?

These are the values contained in my vector:

size(vibration)
ans =
        1024           1
vibration =
   -0.0005
   -0.0006
   -0.0007
   -0.0008
   -0.0010
   -0.0011
   -0.0012
   -0.0013
   -0.0014
   -0.0015
   -0.0016
   -0.0017
   -0.0018
   -0.0019
   -0.0020
   -0.0021
   -0.0022
   -0.0023
   -0.0024
   -0.0026
   -0.0027
   -0.0025
   -0.0003
   -0.0038
   -0.0089
   -0.0035
   -0.0018
   -0.0022
    0.0004
    0.0034
    0.0063
   -0.0023
   -0.0046
   -0.0022
   -0.0043
    0.0041
    0.0025
    0.0024
    0.0037
    0.0050
    0.0060
    0.0012
    0.0058
    0.0019
    0.0008
    0.0009
   -0.0060
    0.0004
    0.0032
   -0.0005
   -0.0008
   -0.0024
    0.0021
    0.0009
   -0.0019
    0.0003
    0.0012
    0.0069
    0.0125
    0.0209
    0.0262
    0.0184
    0.0100
    0.0058
    0.0136
    0.0181
    0.0089
    0.0058
    0.0077
    0.0045
    0.0024
    0.0015
    0.0044
    0.0095
    0.0096
    0.0087
    0.0019
    0.0053
    0.0066
    0.0033
   -0.0010
    0.0010
    0.0116
    

Open in new window

0
This code works for White particles on a black background, can it be tweaked to work for black particles on white background..?Thanks!

 
    RGB=imread('CW5000.jpg');
    s_wavelength=4; ; %use every 4th pixel for the perimeter calculation
    I = rgb2gray(RGB);
    threshold=.4 %black and white threshold
    bw = im2bw(I,threshold);
    imshow(bw)
    bw = bwareaopen(bw,350);
    se = strel('disk',2);
    bw = imclose(bw,se);
    bw = imfill(bw,'holes');
    [B,L] = bwboundaries(bw,'noholes');
    imshow(label2rgb(L, @jet, [.5 .5 .5]))
    hold on
    for k = 1:length(B)
    boundary = B{k};
    plot(boundary(:,2), boundary(:,1), 'y', 'LineWidth', 1)
    end
    stats = regionprops(L,'Area','Centroid','MajorAxisLength','MinorAxisLength')
    for k = 1:length(B)
    boundary = B{k};
    A = size(boundary)
    boundary2=boundary(s_wavelength:s_wavelength:A(1,1),:);
    delta_sq = diff(boundary2).^2;
    perimeter = sum(sqrt(sum(delta_sq,2)));
    area2 = stats(k).Area;
    area=polyarea(boundary2(:,1),boundary2(:,2));
    metric = 4*pi*area/perimeter^2;
    metric_string=sprintf('%2.2f',metric);
    text(boundary(1,2)+0,boundary(1,1)+50,metric_string,'Color','k',...
    'FontSize',12,'FontWeight','bold');
    %text(boundary(1,2)+40,boundary(1,1)+100,metric_string2,'Color','c',...
    %'FontSize',12,'FontWeight','bold');
    %text(boundary(1,2)+30,boundary(1,1)+150,metric_string3,'Color','g',...
    %'FontSize',12,'FontWeight','bold');
    

Open in new window

0
Free Tool: Site Down Detector
LVL 12
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Hi to all,

I have a vector " imu" with a size of 11497 elements. These elements are samples captured at a very high rate (the total time is 71 seconds so I think the frequency is about 160 Hz). Since I acquired all the other values at 10Hz, the size of all my other vectors is 719.

I would like to remove the oversampled elements from the vector " imu" in order to have only 10 samples per second.

Is there any way to do this? Can you help me, please?
0
Hi to all,

i'm having a problem with one of my old matlab scripts.
This script worked very well on a previous version of Matlab, but now I'm running it on a different machine and on a different Matlab version (R2017b) and it gives me this error:

Index exceeds matrix dimensions.
Error in cusum (line 36)
y   = x1(:,c_y) - mean(x1(:,c_y));
Error in original (line 269)
      [ckc,slc]=cusum(Ic(:,2)); %% PROBLEMA 

Open in new window


Please, can you try to help me?
I attached to this post all the matlab files (i renamed them with *.txt extension) and also the txt file to use to populate the vectors.

The main matlab file is 'original.m':

clear all, close all
addpath '/home/rocco/Documents/MATLAB/code/function'
% 
% figure(1)
% set(1,'units','normalized','position',[0.142187 0.484722 0.307813 0.447222],....
%         'name','Path','numbertitle','off');
%     set(gca,'FontSize',11);
% figure(2)
% set(2,'units','normalized','position',[0.457031 0.484722 0.264063 0.447917],....
%         'name','Equivalent track','numbertitle','off');
%     set(gca,'FontSize',11);
%     
% figure(3)
% set(3,'units','normalized','position',[0.009 0.13 0.482031 0.806944],....
%         'name','Terrain estimation','numbertitle','off');
%     set(gca,'FontSize',11);
%     
% figure(4)
% set(4,'units','normalized','position',[0.00351563 0.0465278 0.214453 0.893056],....
%         'name','Path','numbertitle','off');

%% Load data

% First campaign january 2015

Open in new window

0
I am trying to use Matlab 2016 as a neural network. I have large amounts of comma-delimited ASCII data that I would like to analyze. Each row of data contains about 1500 elements of alphanumerics. There would be about 100 records/rows of 1500 elements each. The first task I need to do is determine the correlation, if any, between the various elements. I think that would be a clustering issue. Is it practical, or advised, to try to run the entire block of data at one time, or to pick out what I think are the relevant factors and just analyze those for correlations? I have reasonably powerful computing equipment and I don't know if time factors would make looking at the entire data set prohibitive. Once I determined which way to do that, and have figured out some of the correlations, I would then have to set up an actual neural network to try to get some insight into larger blocks of that same type of data.

Any help will be appreciated and points awarded. Thanks.
0
HI

I have angles of head movements for each video frame in radians ,where positive values yaw correspond to head turning right and

negative values corresponds to head turning to the left .

 I need to calculate movement dynamics ( angular displacement , angular velocity ,angular acceleration )
yaw.csv
untitled.jpg
0
(i) Develop an algorithm to determine whether a graph represented by a node-node incidence matrix is connected or not. Provide a clear algorithm statement.
(ii) Code your algorithm in any programming language you prefer, run your code on the node-node adjacency matrices. The matrix is 300x300. Also, I need to report my results along with the computation time in seconds
0
When I compile my mex with the "-g" argument, a PDB file is created which allows me to Attach to the Matlab Process.

This works OK.

However, I'm finding that if I change any part of the source code, then recompile the mex and Attach to Matlab again, my breakpoints are not ever hit again.

The solution is to exit Matlab, restart Matlab, rebuild the  mex and re-attach.  Then, magically, it works again.

But it's a royal pain to have to continue exiting Matlab every time I make a small code change.

Does anyone know what the solution is?

Thanks,
0
Hi,
I am trying to check integration using two different methods, first by using [function (int)] and second by using summation. I am integration from high to low values (0.1 to 0). I got same result. However, from function I got positive value (0.005) and from summation, negative value (-0.005).  I am not sure if that because I am integrating from high to low values so I need to use (dr) in negative value when finding the integration using summation.

I used below code

 
 clear all;
  clc;
  syms x y 
  y = -x; 
  z=int(y,x);
  v=[0:0.1/19:0.1];
  dr=0.1/20;
  for i=1:20
      x=v(i);  
      kk(i)=eval(y)*(dr);    
  end
  R1=sum(kk(1,:));
  x=0.1;
  z1=eval(z);
  x=0;
  z2=eval(z);
  R2=z2-z1;

Open in new window

0
You can refer to section 4.3.1 in this article if you want.

Problem: Given a reference point and a direction, I need to find the core of a line scratch.


  1. To do that, according to the article, I need to select a prominent point on the line-scratch and that point would be used as the reference point pR.
  2. Then start a search from that reference point, proceeding on both sides of the line along the direction dS.
  3. If pI is our current point at column k (shown in yellow here),
    • take 5 points adjacent to pI at column k+1 (shown in blue here).
    • find the point with the largest similarity value.
    • add the point to the core.

pixel-candidatesWe will use a specific function as the similarity measure. That function uses correlation, among other things, as a measure.

equation
  1. pI is the i-th pixel at the column-k.
  2. w1 and w2 are constants with values 0.75 and 0.25 respectively.
  3. cG is a global correlation factor measured between a matrix centered at pR and another matrix pKi which has a center at pI.
  4. g is a Gaussian function computed at pI.
  5. cL is a local correlation factor measured between a matrix centered at pK_1s and another matrix pKi which has a center at pI.
  6. pK_1s is the last included point at the core.

Implementation
Please, see the source code later in this question.

What is the problem I am facing right now?
 
  1.  I am not sure whether the matrices (i.e. pKi, matrix around pR, pI and so on) I am using are taken correctly.
  2.  I am not sure about the usage of dS.
0
I am very new to image processing and Matlab. I am working with RGB image and used SLIC algorithm to generate superpixel for an image. By using regionprops to calculate the superpixel properties.

[Rcounts binlocations]=imhist(ImageRED);
[Gcounts binlocations]=imhist(ImageGREEN);
[Bcounts binlocations]=imhist(ImageBLUE);
Q1: I have 48 superpixels with Counts(R,G,B channels) it is giving me 256*1 double(most of them are zero). Can anybody explain how to refine them to get each superpixel histogram?

Q2: How can I compare and calculate the distance between two specific superpixel histograms?

Any help is greatly appreciated. Thanks in advance
0
Free Tool: SSL Checker
LVL 12
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

how can I add a constraint for vibration damper in a SUV vehicle model meant to demonstrate a rollover
0
Hi,

I have a covariance matrix and I am using Matlab's chol function for cholesky decomposition. However, since my matrix is not a positive definite matrix. I am getting an error. How can I figure out which correlations/covariances in the matrix are leading to the problem.

Attached file contains the matrix.

Thanks
EE1.xlsx
0
How to write program for  encryption and decryption input text using RC4 algorithm in Matlab?
0
how i can apply fuzzy logic for this problem? Or is there any other technique i can use for my problem?

Input : parameter values Output : (1) OLTP , (2) DSS , (3) % of OLTP and % of DSS

I have to classify between 3 classes as OLTP, DSS and mix type. if my input matches with OLTP or DSS type it return crisp class. if it matches with mix type it returns the percentage of OLTP and DSS
0
How can i apply fuzzy logic for this problem? Or is there any other technique i can use for my problem?

Input : parameter values Output : (1) OLTP , (2) DSS , (3) % of OLTP and % of DSS

I have to classify between 3 classes as OLTP, DSS and mix type. if my input matches with OLTP or DSS type it return crisp class. if it matches with mix type it returns the percentage of OLTP and DSS.
0
Two vehicles update their position using latitude and longitude using .csv file. Plot the graph for two vehicles in a single graph to detect the collision.
0

MATLAB ProgrammingSponsored by Jamf Now

383

Solutions

455

Contributors

MATLAB is a numerical computing environment and proprietary fourth-generation programming language. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, Fortran and Python. Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing capabilities. An additional package, Simulink, adds graphical multi-domain simulation and model-based design for dynamic and embedded systems.

Top Experts In
MATLAB Programming
<
Monthly
>

No Top Experts for this time period. Answer questions to earn the title!