Answered

How to plot polynomial function correctly?

Your code is working fine, the difference is just the axis limits. Try this: d = @(g)1-5*g-2.5*g.^2+6*g.^3+5*g.^4; e = -2:1/10...

How to plot polynomial function correctly?

Your code is working fine, the difference is just the axis limits. Try this: d = @(g)1-5*g-2.5*g.^2+6*g.^3+5*g.^4; e = -2:1/10...

5 days ago | 1

| accepted

Answered

produce all combinations of n choose k in binary

One option (Probably a better implementation can be done, but this one should work): n = 5; k = 3; comb = nchoosek(1:n,k); ...

produce all combinations of n choose k in binary

One option (Probably a better implementation can be done, but this one should work): n = 5; k = 3; comb = nchoosek(1:n,k); ...

16 days ago | 0

Answered

I have daily data from 1969 to 2018. I want to remove the rows corresponding to 29-02 day from the matrix. How should I proceed?

Another option: [~,~,raw] = xlsread('sample.xlsx'); raw(contains(raw(:,1),'29/02'),:) = [];

I have daily data from 1969 to 2018. I want to remove the rows corresponding to 29-02 day from the matrix. How should I proceed?

Another option: [~,~,raw] = xlsread('sample.xlsx'); raw(contains(raw(:,1),'29/02'),:) = [];

16 days ago | 0

Answered

How I input an array of numbers in GUI text box?

Use str2num instead: x=str2num(get(handles.edit1,'string'));

How I input an array of numbers in GUI text box?

Use str2num instead: x=str2num(get(handles.edit1,'string'));

17 days ago | 0

Answered

How to remove NaN's from an array AND the corresponding value/element in another array of the same size?

x1 = A(~isnan(B)); y1 = B(~isnan(B));

How to remove NaN's from an array AND the corresponding value/element in another array of the same size?

x1 = A(~isnan(B)); y1 = B(~isnan(B));

17 days ago | 1

| accepted

Answered

Problem with loop index

A simple way to do that avoiding the loop is: idx = ismember(FinAti.Data,rm_zerohoras); FinAti(idx,:) = [];

Problem with loop index

A simple way to do that avoiding the loop is: idx = ismember(FinAti.Data,rm_zerohoras); FinAti(idx,:) = [];

20 days ago | 0

| accepted

Answered

How can I make each cell array consistent in size?

N = max(cellfun('size',P,1)); M = max(cellfun('size',P,2)); newP = cellfun(@(x) [x, zeros(size(x, 1), M-size(x, 2)); zero...

How can I make each cell array consistent in size?

N = max(cellfun('size',P,1)); M = max(cellfun('size',P,2)); newP = cellfun(@(x) [x, zeros(size(x, 1), M-size(x, 2)); zero...

23 days ago | 0

| accepted

Answered

Reshape the vector as indexed matrix.

Yes, just removing the for loop because this loop doesn't do anything in your code.

Reshape the vector as indexed matrix.

Yes, just removing the for loop because this loop doesn't do anything in your code.

23 days ago | 0

Answered

i received an error (index must be a positive integer or logical. Error in Guassseidal3 (line 24) U(i,0)=0;) in solving PDE problems. plz help me to get out of this problem.

0 is not a valid index in Matlab. To take the first element you should put 1: U(i,1)=0;

i received an error (index must be a positive integer or logical. Error in Guassseidal3 (line 24) U(i,0)=0;) in solving PDE problems. plz help me to get out of this problem.

0 is not a valid index in Matlab. To take the first element you should put 1: U(i,1)=0;

23 days ago | 0

Answered

Need to remove elements which repeated 2 times

A=[1 2; 1,3; 1,4; 1,5; 2,3; 3,6; 4,5; 5,6]; N=max(max(A)); A_new = A; for i=1:N if sum(sum(A==i),2)==2 A_new(an...

Need to remove elements which repeated 2 times

A=[1 2; 1,3; 1,4; 1,5; 2,3; 3,6; 4,5; 5,6]; N=max(max(A)); A_new = A; for i=1:N if sum(sum(A==i),2)==2 A_new(an...

26 days ago | 0

| accepted

Answered

How to store values in matrix with similar index number of other matrix?

A_new = B(A)

How to store values in matrix with similar index number of other matrix?

A_new = B(A)

26 days ago | 0

| accepted

Answered

How can I make each cell array consistent in length?

Do you mean this? N = cellfun(@numel, T_mon); M = max(N); T_mon_new = cellfun(@(a) [a; zeros(M - numel(a),1)],T_mon,'uni',0);...

How can I make each cell array consistent in length?

Do you mean this? N = cellfun(@numel, T_mon); M = max(N); T_mon_new = cellfun(@(a) [a; zeros(M - numel(a),1)],T_mon,'uni',0);...

27 days ago | 0

| accepted

Answered

I get the following error "Dimensions of arrays being concatenated are not consistent."

Are you defining row vectors? Use ... in each line w20=[2.22939364554e-13,4.39934099226e-10,1.08606937077e-7,... 7.8025564785e...

I get the following error "Dimensions of arrays being concatenated are not consistent."

Are you defining row vectors? Use ... in each line w20=[2.22939364554e-13,4.39934099226e-10,1.08606937077e-7,... 7.8025564785e...

1 month ago | 0

| accepted

Answered

Index exceeds array elements

The problem is in this line (you are changing the size of the array inside the loop): guess_vector(j) = [] One option could be...

Index exceeds array elements

The problem is in this line (you are changing the size of the array inside the loop): guess_vector(j) = [] One option could be...

1 month ago | 0

Answered

How do I record the entire row of a matrix if it has a peak value in the third column?

Try this: [~,locs] = findpeaks(xyK(:,3)); sol = xyK(locs,:);

How do I record the entire row of a matrix if it has a peak value in the third column?

Try this: [~,locs] = findpeaks(xyK(:,3)); sol = xyK(locs,:);

1 month ago | 0

| accepted

Answered

repeating a sequence of code

Do you mean this? n = 1; while n ~= 3 disp(' Choose an Option Below '); disp(' 1 Convert Decimal Number to Binary ...

repeating a sequence of code

Do you mean this? n = 1; while n ~= 3 disp(' Choose an Option Below '); disp(' 1 Convert Decimal Number to Binary ...

1 month ago | 0

| accepted

Answered

creating array with entries as numbers

Do you mean this? n = 1.44:0.001:1.45;

creating array with entries as numbers

Do you mean this? n = 1.44:0.001:1.45;

1 month ago | 0

Answered

More efficient "for i in array" loops

Using your equations directly: x = [1 2 3 4 5 6]; c = 1; cos_theta = (1-((2*x)/c)); theta = acos(cos_theta);

More efficient "for i in array" loops

Using your equations directly: x = [1 2 3 4 5 6]; c = 1; cos_theta = (1-((2*x)/c)); theta = acos(cos_theta);

1 month ago | 0

Answered

My code won't run. It says there is an error in line 30.

There is an error in your calls to matlabFunction: function [] = Newton(f, x1, tol, N) % % Newton uses Newton’s method to app...

My code won't run. It says there is an error in line 30.

There is an error in your calls to matlabFunction: function [] = Newton(f, x1, tol, N) % % Newton uses Newton’s method to app...

1 month ago | 0

Answered

How to remove multiple elements in a row matrix

This is a very basic problem. I recommend you to do the Matlab tutorial Being A your array: A = A(2835:end);

How to remove multiple elements in a row matrix

This is a very basic problem. I recommend you to do the Matlab tutorial Being A your array: A = A(2835:end);

1 month ago | 0

Answered

Converting matirx into vektor inside a cell array

Try with this: for i=1:n for j=1:m ev1{j,i} = V{j,i}(:,1); ev2{j,i} = V{j,i}(:,2); end end

Converting matirx into vektor inside a cell array

Try with this: for i=1:n for j=1:m ev1{j,i} = V{j,i}(:,1); ev2{j,i} = V{j,i}(:,2); end end

1 month ago | 0

| accepted

Answered

campare a row value with the next row

Another option: a = [1;1;0;0;0;1;0;1;0;1]; b = diff(a); b(~b) = 2*a(~b); sol = splitapply(@numel,b,b+2) %Ordered as [1,0],...

campare a row value with the next row

Another option: a = [1;1;0;0;0;1;0;1;0;1]; b = diff(a); b(~b) = 2*a(~b); sol = splitapply(@numel,b,b+2) %Ordered as [1,0],...

1 month ago | 1

Answered

Solve a quadratic equation

To use the function roots you need to reformulate your equation: tau = 0.1 f4 = [3; 2; 6; 8] f8 = [2; 6; 7; 3] eq = @(f4,f...

Solve a quadratic equation

To use the function roots you need to reformulate your equation: tau = 0.1 f4 = [3; 2; 6; 8] f8 = [2; 6; 7; 3] eq = @(f4,f...

1 month ago | 0

| accepted

Answered

Error: Attempt to execute SCRIPT mesh as a function

Because your live script has the same name than the function mesh and when you call this function, in fact you are calling your ...

Error: Attempt to execute SCRIPT mesh as a function

Because your live script has the same name than the function mesh and when you call this function, in fact you are calling your ...

1 month ago | 0

| accepted

Answered

Index exceeds the number of array elements (1).

VarHigh is a constant and you are using it as an array... VarHigh(2) %Throws an error

Index exceeds the number of array elements (1).

VarHigh is a constant and you are using it as an array... VarHigh(2) %Throws an error

1 month ago | 0

Answered

How would I write this code without using loops?

Another option: N = 1000; five = 2*5:5:N; seven = 2*7:7:N; res = setxor(five,seven)

How would I write this code without using loops?

Another option: N = 1000; five = 2*5:5:N; seven = 2*7:7:N; res = setxor(five,seven)

2 months ago | 0

Answered

Hold on Not showing all of my plots on one graph

Take a look at the variables you are plotting, they are duplicated. I mean Bsigmay is equal to sigmay, Bsigmaz is equal to sigma...

Hold on Not showing all of my plots on one graph

Take a look at the variables you are plotting, they are duplicated. I mean Bsigmay is equal to sigmay, Bsigmaz is equal to sigma...

2 months ago | 0

| accepted

Answered

How do I use a vector as a set of indices?

Try this: m = 5000; num_labels = 10; y = randi(num_labels,m,1); yrec = zeros(num_labels,m); yrec(sub2ind(size(yrec),y',1:...

How do I use a vector as a set of indices?

Try this: m = 5000; num_labels = 10; y = randi(num_labels,m,1); yrec = zeros(num_labels,m); yrec(sub2ind(size(yrec),y',1:...

2 months ago | 0

| accepted