Answered

Creating a new variable in a loop automatically. Please help!

You can use the eval function to create such variables. However this practice is not recommended and can almost always be circum...

Creating a new variable in a loop automatically. Please help!

You can use the eval function to create such variables. However this practice is not recommended and can almost always be circum...

8 years ago | 0

| accepted

Answered

Several vectors as inputs to function

It all depends whether your function BSCall supports vector input. If it does, then just Values=BSCall(S,K,T,v,r) with ...

Several vectors as inputs to function

It all depends whether your function BSCall supports vector input. If it does, then just Values=BSCall(S,K,T,v,r) with ...

8 years ago | 0

Answered

How can I substitute values in a matrix if they equal a certain value?

I hope this is what you mean: newmatrix=X1; newmatrix(X1==255)=X2(X1==255);

How can I substitute values in a matrix if they equal a certain value?

I hope this is what you mean: newmatrix=X1; newmatrix(X1==255)=X2(X1==255);

8 years ago | 0

Answered

How to sort rows of a 2D array, such that all elements along a diagonal are non-zero?

For reference, here is a solution using the backtracking. The main algorithm part is around 20 lines. This is the initial s...

How to sort rows of a 2D array, such that all elements along a diagonal are non-zero?

For reference, here is a solution using the backtracking. The main algorithm part is around 20 lines. This is the initial s...

8 years ago | 1

Answered

how to make a spatial plot?

Assuming your dataset are vectors, you could simply make a scatterplot scatter(longitude, latitude, 5, rain); Alternativ...

how to make a spatial plot?

Assuming your dataset are vectors, you could simply make a scatterplot scatter(longitude, latitude, 5, rain); Alternativ...

8 years ago | 1

| accepted

Answered

formal initialisation of matrix

Answering your second question A=bsxfun(@eq,x,y');

formal initialisation of matrix

Answering your second question A=bsxfun(@eq,x,y');

8 years ago | 0

| accepted

Answered

formal initialisation of matrix

Three alternative solutions posted here: <http://stackoverflow.com/questions/13767832/how-do-i-create-a-matrix-whose-elements...

formal initialisation of matrix

Three alternative solutions posted here: <http://stackoverflow.com/questions/13767832/how-do-i-create-a-matrix-whose-elements...

8 years ago | 0

Answered

how do you increment a count and repeat a code multiple times

For random numbers between 0 and 10 count1=0; count2=0; for p=1:10000 a1=round(rand(1)*10); b1=round(r...

how do you increment a count and repeat a code multiple times

For random numbers between 0 and 10 count1=0; count2=0; for p=1:10000 a1=round(rand(1)*10); b1=round(r...

8 years ago | 0

Answered

Ordering a column with respect to another column.

This should do it: A=rand(50,2); [~,J]=sort(A(:,2),'descend'); A(J,1)=sort(A(:,1),'ascend'); corr(A(:,1), A(:,2) ,...

Ordering a column with respect to another column.

This should do it: A=rand(50,2); [~,J]=sort(A(:,2),'descend'); A(J,1)=sort(A(:,1),'ascend'); corr(A(:,1), A(:,2) ,...

8 years ago | 0

| accepted

Answered

How to make and sum up a matrix with upper diagonal direction without for-loop condition [The fastest way!]

Here is one way, which avoids making the B matrix (it directly gives the sum you want, so should be faster on large matrices) ...

How to make and sum up a matrix with upper diagonal direction without for-loop condition [The fastest way!]

Here is one way, which avoids making the B matrix (it directly gives the sum you want, so should be faster on large matrices) ...

8 years ago | 0

Answered

How to Output Accurate PDF from Matlab figure

The problem with the spacing is in fact a problem of the line around the circle. Because you work on such small scales, it deter...

How to Output Accurate PDF from Matlab figure

The problem with the spacing is in fact a problem of the line around the circle. Because you work on such small scales, it deter...

8 years ago | 0

| accepted

Answered

How can I delete rows in a matrix where two numbers exist side-by-side?

This should do the job. If you have a huge matrix and you want it to go faster, you will need to adapt this code to build up a v...

How can I delete rows in a matrix where two numbers exist side-by-side?

This should do the job. If you have a huge matrix and you want it to go faster, you will need to adapt this code to build up a v...

8 years ago | 0

| accepted

Answered

How to create contour plot?

First you will need to calculate your electrical field as a function of x and y, to yield a matrix. Then you can simply use mat...

How to create contour plot?

First you will need to calculate your electrical field as a function of x and y, to yield a matrix. Then you can simply use mat...

8 years ago | 0

Answered

Sort a vector according to another vector

[~,Bsort]=sort(B); %Get the order of B C=A(Bsort) C = 1 9 4 5 8

Sort a vector according to another vector

[~,Bsort]=sort(B); %Get the order of B C=A(Bsort) C = 1 9 4 5 8

8 years ago | 4

| accepted

Answered

how to count the occurrences of a value for an matrix?

c=unique(a); b=[c, sum(bsxfun(@eq,a(:),c'))'] b = 3 3 4 2 5 2 6 3 7 ...

how to count the occurrences of a value for an matrix?

c=unique(a); b=[c, sum(bsxfun(@eq,a(:),c'))'] b = 3 3 4 2 5 2 6 3 7 ...

8 years ago | 0

| accepted

Answered

i have 729 data points within a particular range of lat &long. how can i reduce this to 150 without changing the range of lat&long..?

This should do it: lat=rand(729,1); step=729/149; latshort=[lat(1:step:end-1); lat(end)]

i have 729 data points within a particular range of lat &long. how can i reduce this to 150 without changing the range of lat&long..?

This should do it: lat=rand(729,1); step=729/149; latshort=[lat(1:step:end-1); lat(end)]

8 years ago | 0

| accepted

Answered

logical operation on a column within a matrix

This should work: POS(POS(:,2)==0,2)=1;

logical operation on a column within a matrix

This should work: POS(POS(:,2)==0,2)=1;

8 years ago | 0

| accepted

Question

Speed optimization of partial inner product (norm)

For a row vector, the norm can be written as sqrt(sum(P.^2)) or sqrt(P*P') The latter is about twice as fast. No...

8 years ago | 2 answers | 0

Answered

fill a polygon with a hole

Alternatively, you can remove all black lines (like that the figure looks good to me) h=fill(data(:,1),data(:,2),'r','Lines...

fill a polygon with a hole

Alternatively, you can remove all black lines (like that the figure looks good to me) h=fill(data(:,1),data(:,2),'r','Lines...

8 years ago | 0

| accepted

Answered

how can i plot 3 parameters in asingle graph(as shown in the picture)..two of them along x&y axis and one parallel to x-axis?

Perhaps this helps: <http://www.mathworks.nl/help/matlab/creating_plots/using-multiple-x-and-y-axes.html>

how can i plot 3 parameters in asingle graph(as shown in the picture)..two of them along x&y axis and one parallel to x-axis?

Perhaps this helps: <http://www.mathworks.nl/help/matlab/creating_plots/using-multiple-x-and-y-axes.html>

8 years ago | 0

Answered

Hello everyone. I converted 4 into binary and got 100 . my problem is that i want to use this 100 as a decimal but the matlab is obviously treating it as a binary number. Please help

The following code gives you a decimal 100: str2double(dec2bin(4))

Hello everyone. I converted 4 into binary and got 100 . my problem is that i want to use this 100 as a decimal but the matlab is obviously treating it as a binary number. Please help

The following code gives you a decimal 100: str2double(dec2bin(4))

8 years ago | 0

Answered

Flipping one Y axis out of two

I hope this is what you had in mind. To make sense of it, I think you need to display 2 Y-axis, the example below does that. ...

Flipping one Y axis out of two

I hope this is what you had in mind. To make sense of it, I think you need to display 2 Y-axis, the example below does that. ...

8 years ago | 0

| accepted