MATLAB Programming

371

Solutions

441

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

As a part of my project, I want to encrypt user defined data using an unbreakable encryption algorithm. I have got one AES algorithm. But it accepts plaintext as
 plaintext_hex = {'00' '11' '22' '33' '44' '55' '66' '77' ...
                 '88' '99' 'aa' 'bb' 'cc' 'dd' 'ee' 'ff'};
I am doing my project in matlab.
0
Free Tool: Subnet Calculator
LVL 8
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question :You are to simulate the motion of a drunken sailor (i.e. a random walk problem).  The sailor is standing at the middle of a pier on the shore side.  The sailor’s ship is directly across from him.The pier size is L paces long and W paces wide (i.e. the sailor starts at coordinates ½ W, 0 and the ship is L paces away) and the ship stretches across the entire width of the pier.Due to the sailor’s inebriated condition a straight walking path cannot be maintained.  Each second the sailor attempts to take a step.  There is a 25% chance that the sailor will go left, a 20% chance the sailor will go right, a 10% chance the sailor will stand still, and a 45% chance the sailor will go forward.  Assume the sailor does not go backwards.If the sailor’s position exceeds the dimensions of the pier (zero to W) they fall into the sea.  If they make it to the other side they are safe at their ship.Write a  Matlab program(script file) that takes L and W as user inputs.  The motion of the sailor is then simulated.  If the sailor falls into the sea an appropriate message should be output.  If the sailor makes it to the ship the time and number of paces it took them should be output.  For either case a plot showing the sailor’s path should be made.
Hint: Use evenly distributed random numbers to determine what direction the sailor goes.
0
I want to find dct of a matrix in c++ just like how it is done in matlab.
Below is the code I used
#include <fftw3.h>
using namespace std;
 double** create2DArray(int row, int col)
{
	 double** arr = new  double*[row];
	for(int i = 0; i < row; i++)
		arr[i] = new  double[col];
	return arr;
}

int main()
{
int m = 3; 
int n = 3;
 	
      /*double a[m][n] =
   	 {
        {0.2, 0.3 ,1},
        {0 ,12 ,5},
        {0.3, 0.3, 1}
   	 };*/

   double** a= create2DArray(m,n); 
   for( int j = 0; j < m;j++ ) 
  	{	
  		for(int i = 0; i < n; i++)
	   		{	
    						a[i][j] = Signal[i]*hamming[i];
			}
  	 }

   double** b= create2DArray(m,n);   
   
    printf("Original vector\n");
	for(int i=0;i<m;i++)
	 {    
	  for(int j = 0 ;j<n;j++)
	     {
	        cout << a[i][j] <<"  " ;
	     }
	cout<< endl;
	}
  
    

    fftw_plan plan = fftw_plan_r2r_2d(n, m,&a[0][0],&b[0][0], FFTW_REDFT10, FFTW_REDFT10, FFTW_ESTIMATE);
    fftw_execute(plan);
      
    printf("DCT\n");
    for(int i=0;i<m;i++)
	{    
	for(int j = 0 ;j<n;j++)
		{
	cout << b[i][j] <<"  " ;
		}
	cout<< endl;
	}

    
    fftw_plan plani = fftw_plan_r2r_2d(n, m,&b[0][0],&a[0][0], FFTW_REDFT01,  FFTW_REDFT01,FFTW_MEASURE);
     fftw_execute(plani);
    
    printf("IDCT\n");

    
   	for(int i=0;i<m;i++)
	{    
	for(int j = 0 ;j<n;j++)
		{
	cout << a[i][j]/(m*n*4) <<"  " ;
		}
	cout<< endl;
	}
   
  
    return 0;
    

Open in new window


1) Matrix a[m][n] is obtained by multiplying signal with hamming window .
2) When I pass Matrix "a" as input to     " fftw_plan plan = fftw_plan_r2r_2d(n, m,&a[0][0],&b[0][0], FFTW_REDFT10, FFTW_REDFT10, FFTW_ESTIMATE); "
I get the following error :
 cannot convert ‘long double*’ to ‘double*’ for argument ‘4’ to ‘fftw_plan_s* fftw_plan_r2r_2d(int, int, double*, double*, fftw_r2r_kind, fftw_r2r_kind, unsigned int)’

How do I pass a matrix  to DCT function using fftw3 ,which is declared as mentioned above .
PS :When I declared it as double a[m][n] = {//Enter the elements}; //when m =640 ; n = 645
It gives Segmentation fault
{Because of which I tried to define matrix a in heap as mentioned but when given to the dct function throws error .}

Can anyone kindly solve my issue .
Thanks in Advance.
0
So I was trying to convert my matlab codes to c++ codes .I was trying to compare the output of all the user defined function written in matlab and c++ . In terms of precision there was slight difference . Something like   " 0.0822219583523415  " the output from matlab   and " 0.082222" from c++ . I ignored such difference at first as the result was similiar to some extent .But when operations like DCT and IDCT is done on vectors with such difference in values , the output I obtained from matlab and c++ DCT /IDCT was very different .
How can I solve this problem ?
0
First of all thank you for your help in advance. My question is regarding Matlab and non-linear Least Square curve fitting in Matlab - in both I am not familiar with.

I have this type of data:

x = [600, 800, 1000, 1200, 1400]; 
y = [0, 02, 04, 0.7, 1];

Open in new window


I am trying to use the following algorithms:

f = @(p,x) (p(3)-p(4))./(1+exp(-(x-p(2))/p(1)))+p(4); 
opts = optimset('Display','off','MaxFunEvals',1000); 
sigfit = lsqcurvefit(f, starting_value, intervals,problong,[],[],opts); 
bisection_point= sigfit(2)-sigfit(1)*log((sigfit(3)-0.5)/(0.5-sigfit(4)))

Open in new window


The only problem I have is the starting value in sigfit variable. What would be the best starting values given the above numbers? Any help please would be extremely appreciated.

The above algorithms are based on lsqcurvefit function found in Matlab. Here is the link: http://uk.mathworks.com/help/optim/ug/lsqcurvefit.html

The X vector is time intervals in milliseconds, whereas the Y vector represents responses some participant made whether those intervals where perceived as close to a short (400ms) or long (1600ms) interval.

I don't understand what starting points mean. Ultimately what I need to do is find the 0.5 point in the Y axis and the corresponding value on the X axis. The solution will be somewhere between 600ms to 1400 ms and probably around the 1200ms mark. I have put the starting value as a vector from 600 to 1400 but, I have no idea whether that is right or what that means. I was hoping someone better equipped than me can help answer this problem precisely :).

Thank you again,
Dritan
0
1) The MS Office I used for over 4 years was removed because W10 said that this "starter" office could cause damage.

2) Matlab starts up really fast. But when I enter a command and hit return, the command window gets stuck. In the admin account (which I rarely use), Matlab worked. (I will try re-installing it to see if that helps.) If you have any other suggestions other than reinstalling, I will give them a try.

I ran from the command prompt:
 slmgr /xpr
 and the popup said that Windows is permanently activated.
0
Let's say I already have a function like this
function Result = z(x, y)
Result=-x*y;

Open in new window

Given that function I want to solve this ODE. (the RHS comes from that function)
>> dsolve('Dy=-x*y','y(0)=2','x')
ans =
2*exp(-x^2/2)

Open in new window

However I don't want to update the second bit of code every time the first changes. I was wondering if there's a way for the result to be automatically updated.
0
As an example I could type this to solve an equation analytically
>> dsolve('Dy=-x*y','y(0)=2','x')
ans =
2*exp(-x^2/2)

Open in new window

I would like to evaluate this result numerically eg typing f(2) and the previous result (2*exp(-x^2/2)) would evaluated at 2 giving 0.2707
I could copy paste the previous result and make a a function like this, but I would prefer it to be automatic, otherwise I have to copy paste every time the original function changes.
function y = f(x)
y=2*exp(-x^2/2);

Open in new window

0
I need to implement the equation in attached picture in matlab. It involves 2 summations from 0 to infinity and bessel functions, and I am not sure if I am doing it correctly. Below is my code for the summations. The results I get for the final C value of the whole equation seem reasonable. However, I am questioning my implementation because I have to break out of the loop when my bessel functions evaluate to too large or small. I was wondering if anyone can comment on that, thank you.

sumn = 0;
sumnP = inf;
n = 0;

while abs(sumnP - sumn) > 1e-16
    % m-summation
    summ = 0;
    summP = inf;
    m = 0;
    while abs(summP - summ) > 1e-16
        summP = summ;
        if besseli(2*m+1,(2*n+1)*pi*a/L) ~= 0
        summ = summ + (cos(2*m+1)*ksi*cos(2*m+1)*delta/((2*m+1)^2))...
            *besseli(2*m+2,(2*n+1)*pi*a/L)/besseli(2*m+1,(2*n+1)*pi*a/L);
        else break
        end
        m = m + 1;
        if isnan(summ)
            summ = summP; break;
        end
    end
    sumnP = sumn;
    sumn = sumn + (-1)^n*sin((2*n+1)/2)*(pi*len/L)*summ;
end
equation.jpg
0
Is  there some application that can Convert C# to MATlab ?
0
Enroll in June's Course of the Month
LVL 8
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

In MATLAB I need to parse or split the following string 'E4'.  I want to be able to split 'C4' and 'C3' and compare the two numbers.  How can I do this?
Thanks
0
Experts,

So, I'm trying to repackage a MATLAB MCR, which is a compressed file that unpacks before it installs, using AdminStudio Repackager. I'm getting this line in the conversion:
"No INSTALLDIR definition was found in the options.ini file" - which is true...
Which results in an unsuccessful build, in the end. From my research, it's something about building from/to root C (C:\), but I'm working out of C:\Packages.

Any ideas?
0
I can not find how to use database explorer app in Matlab. I searched online and there are many tutorials teaching Database Explorer for Matlab 2012 but not 2011. I wonder how to do it from R2011a.

Seems like no one know about it. Maybe some experts here know something about it.

Thanks.

Jennifer
0
Hi,

I am using MATLAB R2011a (64bit) and try to connect to SQL SERVER but keep getting connection error. Should I use ODBC or JDBC. How to use them to connect?

Thanks.

Jennifer
0
Can somebody point me to a complete tutorial that guide to MATLAB, that teaches
1. create a project
2. create function that pull data from SQL Server
3. make the executable

I am very new to MaTLab but I am face this urgent project (deadline) so I need a crush course.

Thanks in advance for every help.

Jennifer
0
Hi,

I know the basics of MatLab. But I need to learn the programming part of it to use it as programming in C++. Could anyone point me to a sample programming  in MatLab or tutorial?

Thanks,

Jennifer
0
How to solve this:
y”+7y+5=0 , y(0)=2 ,y(0)=3
on matlab

Thanks
0
One of the common pain points is the use of Matlab on windows and ability to have access to it (and other windows apps) remotely. We are wanting to propose some options of windows remote desktop and managed desktops/think client access.

Any idea or suggestion ?
0
I need to parse a string of characters MTMSTNNCESMTSYFTNSYMGADMHHGHYPGNGVTDLDAQQMHHYSQNPNQQGNMPYPRFPPYDRMPYYNGQGMDQQQQQH

for Each individual character into its own cell in a matrix.

As example first character goes in cell 1,1, second character goes into cell 1,2, third into 1,3 and so forth.

I need to do this using Mat Lab - also I am new to Mat Lab
0
Free Tool: Path Explorer
LVL 8
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I am trying to get the dicom file info (just an image filetype) for a file name but I keep on getting the error when I put the command in as follows


>> info = dicominfo (//Datacentre/Shares/Users1/SSZ20/Desktop/AC_CT_2001_CT001.dcm)


 info = dicominfo (//Datacentre/Shares/Users1/SSZ20/Desktop/AC_CT_2001_CT001.dcm)
                   |
Error: Unexpected MATLAB operator.

I dont know what Im doing wrong. Help
0
Hi

I have matlab version 2009. When i try to read in a file that has 63174528 floats (ie 252698112 bytes),  I end up with an array that has lesser number of numbers. I understand that matlab treats numbers as doubles i.e. 8 bytes , but even so, I should have plenty of memory to store 63174528 doubles (i.e. 505396224 bytes)

When i run the memory command in matlab to check out my system resources, here is what i get
>memory

Maximum possible array:              28069 MB (2.943e+010 bytes) *
Memory available for all arrays:     28069 MB (2.943e+010 bytes) *
Memory used by MATLAB:                 659 MB (6.915e+008 bytes)
Physical Memory (RAM):               16361 MB (1.716e+010 bytes)

*  Limited by System Memory (physical + swap file) available.


So as you can see, 28069 MB, is plenty of space to accomodate my file of numbers in an array.

my matlab code is as follows:
fid=fopen(filename);
data=fread(fid,'float32');

Here, I get data as <14598144x1 double> array. I am missing some 600,000 numbers.

Can anyone advise as to what can be done to accomodate 63174528 numbers in an array and why the array is so small when the memory command lists far more memory being available.

PS: the file was written out in the following way in C++:
FILE *fp=fopen("myfile.txt","wb");
fwrite((void*)f,sizePerElement,numElements,fp) //dump bytes pointed by a pointer f into the binary file



thanks
0
Can someone advise if there are any C# Matrix Librarys implementing multi-dimensional matrix objects with Matlab(TM) type functionality (eg transpose( ), reshape( ), permute( ) ) ?   An open source or royalty free library would be preferred.
0
n00b on matlab syntax any thoughts to the following ? thx


clc, clear

x = [0:20];
y = 0.0039*x.^3 + 0.78*x.^2 + 39.9*x - 467; 
yp = 0.0117*x.^2 - 1.56*x +39.9;

plot(x,y)
[x_guess,y_guess] = ginput(1)

xi(1) = x_guess;

i=1;
err = 1;



while (err > .0001)
   i=i+1; %increment
   y = 0.0039*xi(i-1).^3 + 0.78*xi(i-1).^2 + 39.9*xi(i-1) - 467;
   yp = 0.0117*xi(i-1).^2 - 1.56*xi(i-1) +39.9;
   xi(i) = xi(i-1) - (y/yp);
   err(i) = abs((xi(i)-xi(i-1))/xi(i));   %BROKEN HERE
end
xi

plot(1:i,err)


%its sorta working but not its not getting out of that while loop 
% GOAL : find the X value where error is less than .0001

Open in new window

0
Hi to all,

I need to read data from an old sensor which use a serial port to send packets.
I think it would be better for me to use C/C++ under Ubuntu.

In the sensor manual, packet format is explained in this way:

Each data packet begins with a header byte (255) and end with a
checksum. The checksum is calculated in the following manner:
1. Sum all packet contents except header and checksum.
2. Divide the sum by 256.
3. The remainder should equal the checksum.

The header byte 0xFF will likely not be the only 0xFF byte in the data
packet. You must count the bytes received at your serial port and use the
checksum to ensure you are in sync with the data sent by the DMU. This is
especially critical when using the continuous data packet output mode.
I attached to this topic a table with all fields contained in a single packet.

I also have a matlab code which is able to read the packet, but I'm not able to understand what it does.

input='FFFFB30029FF86FF8A0009FFD5FFB22AC20632A48CCB';

if strcmp(input(1:2),'FF')
    input=input(3:end);
    s=length(input)-2;
    n=s/4;
for i=1:n
    a(i,1:4)=input(4*(i-1)+1:4*i);
end

for i=1:n
    str=a(i,:);
    %% Checksum
    %ch(i,1)=hex2dec(str);
if hex2dec(str(1))>=8
   o1(i,1)=hex2dec(str)-2^16;
else
   o1(i,1)=hex2dec(str);
end
end
o1

sfr=100*1.5/2^15;
sfa=2*1.5/2^15;
sfan=180/2^15;;

o1sc(1:2,1)=o1(1:2,1)*sfan; % (deg) Roll and Pitch 
o1sc(3:5,1)=o1(3:5,1)*sfr; %deg/s Tilt rate
o1sc(6:8,1)=o1(6:8,1)*sfa; % g 

Open in new window

0
Hi

I have inserted a data set in distribution fitting tool in MAT LAB in order to select the best distribution. Unfortunately, it gives me some distribution which I don't need them. So, how can find more distribution like Uniform dist?
0

MATLAB Programming

371

Solutions

441

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!