matlab

How can I merge this data in MATLAB?

In the sample text file below, if column 3 contains a 1 then the corresponding data of column 2 should be merged with the data of the previous row in column 2. For example, the 40 in row 2 should be added to the 10 in row 1, then row 2 should be set to 0 (as shown in the modified sample text file). The problem with my code below is that ...

How to calculate value of short options call with Black-Scholes formula?

Hello, I am trying to calculate the profit/loss of a short call at various times in the future, but it isn't coming out correct. Compared to the time of expiration, the ones with time left have less profit above the strike price, but at some point below the strike they don't lose value as fast as the t=0 line. Below is the formula in pse...

What types of projects is Mathematica good for?

I once saw a dismal comparison of Matlab vs Mathematica. As you can see Matlab achieves the same with very little code. It looks highly efficient to an untrained eye, so I ask, what types of projects is Mathematica good for? Are there any scientific research problems that are easier solved with it? or is Matlab better for almost every co...

subtracting one image from another

how can i subtract one image from another either row wise or column wise ? ...

Execute file from matlab

Hi my friends. I have a simulink model in Matlab. how can I build excute file from that model? ...

MATLAB how to use FIND function with IF statement

This question is related to http://stackoverflow.com/questions/3071558/matlab-how-to-merge-data how to use the FIND function with IF statement? e.g. if I have this data: 20 10 1 20 11 1 20 15 1 23 10 1 23 10 1 23 12 0 Rule 1: Data of column 3 must be 1. Rule 2: If n is the current index of column 1, if n equal n-1 (20=2...

matlab pcode openning

hi, is there a way to open a pcode (.p) file in matlab? ...

fortran to matlab

Hello, I have a following fortran program: program test implicit none real :: a, b, c read*,a read*,b c=a*b if(c<0)then print*,"OK" else print*,"NOT OK" endif end I want to use this program with MATLAB with S-function, but I don't know any ways. Can you help me ? can you help me? ...

Equivalent of matlab 'ans' in R

In matlab, you can re-use the result of the (non affected) preceding calculous: it is stored in variable ans. Does R has something equivalent ? ...

Setting the number of Maximum iterations in MATLAB

Hi, I want to know how I can set the number of Maximum Iterations(want to increase it) in MATLAB. Does anybody knows? I am using svmtrain ...

Matlab how to ignore the first index=1

The code below gives me error = Subscript indices must either be real positive integers or logicals.Because the first index using FIND function is i=1, the i-1 gives negative value. How to ignore when i==1 without using the LOOP function fid=fopen('data.txt'); A=textscan(fid,'%f%f%f%f'); fclose(fid); in = cell2mat(A); i = find(in(1:end...

How can I count the number of items using the FIND function in MATLAB?

How can I use the function FIND to count the number of items of a given value instead of using a loop? For example, in the array item below there are 3 occurrences of the number 23, 2 occurrences of the number 22, and 2 occurrences of the number 20. .... for i=2:n if item(i-1)~=item(i) nItem21(i)=1; else nItem21...

matlab string passing in user created program.

@ problems. 1) %Main Function %This Main Function reads Integral, Lower and Upper Limits of Integration %Outputs of Main Function are approximation of the integral, error estimate %and Actual Error ipstring=input('Function String: ','s'); %Read Integral string display('Enter Limits of Integration'); a=input('Lower Limit: '); %Read Lowe...

How can I access nested cell arrays in MATLAB?

I would like to make a nested cell array as follows: tag = {'slot1'} info = {' name' 'number' 'IDnum'} x = {tag , info} And I want to be able to call x(tag(1)) and have it display 'slot1'. Instead I am getting this error: ??? Error using ==> subsindex Function 'subsindex' is not defined for values of class 'cell'. If I call x(1) MA...

How can I read this file in MATLAB?

I have a file named data.dat with the following contents: my name is elyas 123 this is a book 123.450 my father name -2.34e+05 I want load this file into MATLAB and get the following data as output: a = 123 b = 123.450 c = -2.34e+05 name = 'elyas' But I don't know how to do this. Any suggestions? ...

MATLAB combine data

How to combine two data columns into one file. These code should produce a new file which have 2 column. Although it produce 2 column but, the data isn't right where all the data of a were written first followed by data duration fid=fopen('data1.txt'); A =textscan(fid,'%f%f%f%f%f%f%f%f%f%f%f%f'); % read a txt file in = cell2mat(A); %ch...

Skipping outputs with anonymous function in MATLAB

Say I want to create an anonymous function from a m-file-function that returns two outputs. Is it possible to set up the anonymous function such that it only returns the second output from the m-file-function? Example: ttest2 returns two outputs, t/f and a probability. If I want to use the t-test with cellfun, I might only be intereste...

how to obtain histogram data in Matlab

As we know, 'hist' function in Matlab plots the histogram of an array. I need to know the numerical value of each bin. Could you help me please? thanks ...

call matlab in an ssh command from a perl script

Hi i have set up passwordless ssh set up and have perl call ssh -o "BatchMode yes" user@host "runMe.pl arg1 arg2" runMe.pl calls matlab and the function run_online with the given args. nohup matlab -nojvm -nodisplay -r "run_online('$imgfolder/$folder/', '$ARGV[0]$folder', '/homes/rbise/results/mitosis/$ARGV[0]/$folder/')" > out.txt < ...

Libraries for manipulating multivariate polynomials

Hi. I need to write some code that deals with generating and manipulating multivariable polynomials. I'll outline my task with a simplified example. Lets say I am given three expressions: 2x^2, 3y + 1, and 1z. I then need to multiply these together which would give me 6x^2yz + 2x^2z. Then I would like to find the partial derivatives of...