Answered

How can I record value once condition is satisfied by searching a matrix?

newMatrix=yourMatrix(yourMatrix(:,2)<=tol,4:5);

How can I record value once condition is satisfied by searching a matrix?

newMatrix=yourMatrix(yourMatrix(:,2)<=tol,4:5);

1 day ago | 0

Solved

Evil Number

Check if a given natural number is evil or not. Read more at <https://oeis.org/A001969 OEIS>.

3 days ago

Solved

Armstrong Number

Determine whether the given input n-digit number is Armstrong Number or not. Return True if it is an Armstrong Number. An n-D...

3 days ago

Solved

Narcissistic number ?

Inspired by Problem 2056 created by Ted. In recreational number theory, a narcissistic number is a number that is the sum of ...

3 days ago

Solved

Parasitic numbers

Test whether the first input x is an n-parasitic number: <http://en.wikipedia.org/wiki/Parasitic_number>. ( _n_ is the second in...

3 days ago

Solved

Brain Teaser Solver

Write an algorithm to solve this brain teaser: You have a square that is broken into four triangles, the area of three of tho...

4 days ago

Solved

Minimum possible M of the maximum side of a triangle of given area A.

Suppose a triangle has area A. Suppose it has three sides S1, S2, and S3. Suppose M = max([S1 S2 S3]). What is the minimum po...

4 days ago

Solved

matrix zigzag

Unfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix [ 1 2 3 ; 4 5 6 ; 7 8 9 ] the resulting 1-...

7 days ago

Answered

Convert a fixed width char array into a column vector

str2num(reshape(aa,8,[])');

Convert a fixed width char array into a column vector

str2num(reshape(aa,8,[])');

7 days ago | 1

| accepted

Solved

Sub-sequence - 01

Find the length of the longest increasing subsequence in the given array. a=[2,4,2,1,3,5,6] longest increasing subsequen...

8 days ago

Solved

Construct the Seidel-Entringer-Arnold triangle

Several problems in Cody ask us to construct part or all of triangles in which entries follow a pattern. Cody Problems <https://...

9 days ago

Answered

Vectorization of For-If combination

Can't think of any better way to do your problem. Only 1 loop now. x=zeros(1000,1); for i=1:10 x(i:i:10*i)=1; x(2*i:2*i:20...

Vectorization of For-If combination

Can't think of any better way to do your problem. Only 1 loop now. x=zeros(1000,1); for i=1:10 x(i:i:10*i)=1; x(2*i:2*i:20...

11 days ago | 0

| accepted

Answered

How can I measure time on MATLAB?

n=200; A=full(gallery('tridiag',n,1,2,1)); a=[3,6]; b=randn(n,1); for k=1:length(a) tic [L,U]=lu(A+a(k)*eye(n)); t(...

How can I measure time on MATLAB?

n=200; A=full(gallery('tridiag',n,1,2,1)); a=[3,6]; b=randn(n,1); for k=1:length(a) tic [L,U]=lu(A+a(k)*eye(n)); t(...

11 days ago | 0

Answered

How do I sum the points from all the innings of each game on each team?

readtable(); a=table2array();%look at this command opp=sum(a(:,1:9),2); us=sum(a(:,10:18),2); %create new table for printing...

How do I sum the points from all the innings of each game on each team?

readtable(); a=table2array();%look at this command opp=sum(a(:,1:9),2); us=sum(a(:,10:18),2); %create new table for printing...

11 days ago | 0

Solved

Pandigital Multiples of 11 (based on Project Euler 491)

A "Pandigital number of order X" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X>9, the cy...

12 days ago

Solved

Day counter function

Write a function called _day_counter_ that returns the number of Mondays that fell on the first day of the month in a given year...

14 days ago

Answered

Incorrect dimensions for matrix multiplication.

y=((x.^2).*exp(x-4)-x+1)./(2+cos(5*x));%you likely want element-wise operations .* and ./

Incorrect dimensions for matrix multiplication.

y=((x.^2).*exp(x-4)-x+1)./(2+cos(5*x));%you likely want element-wise operations .* and ./

15 days ago | 1

Answered

help me, why is it invalid use of operator?

Not sure if you have additional constraints, but if your functions are all polynomials, the polyint function works well. p=[-.0...

help me, why is it invalid use of operator?

Not sure if you have additional constraints, but if your functions are all polynomials, the polyint function works well. p=[-.0...

15 days ago | 0

Answered

I want to creat the loop of background substraction.

Place all images into a cell array. for m=2:length(image) k{m-1}=image{1}-image{m}; end

I want to creat the loop of background substraction.

Place all images into a cell array. for m=2:length(image) k{m-1}=image{1}-image{m}; end

19 days ago | 0

| accepted

Answered

Replacing elements in matrix

a=[0 0 0 0 ; 1 2 1 2 ; 2 0 0 -1 ; -1 0 -1 -2 ; -2 -2 -2 0]; b=sum(a>0)-sum(a<0); for k=1:length(b) if b(k)<0 for...

Replacing elements in matrix

a=[0 0 0 0 ; 1 2 1 2 ; 2 0 0 -1 ; -1 0 -1 -2 ; -2 -2 -2 0]; b=sum(a>0)-sum(a<0); for k=1:length(b) if b(k)<0 for...

19 days ago | 0

Answered

Finding minimums and maximums of repetitive numbers in a matrix

Might need to filter slightly to smooth data to obtain consistent results. redA=islocalmax(a)&a>.1; greenA=islocalmin(diff([a(...

Finding minimums and maximums of repetitive numbers in a matrix

Might need to filter slightly to smooth data to obtain consistent results. redA=islocalmax(a)&a>.1; greenA=islocalmin(diff([a(...

19 days ago | 1

| accepted

Answered

Get the numbers of rows where values change

b=diff(a);%a being your matrix c=find(b(:,1)~=0|b(:,2)~=0);%c=3,5,7

Get the numbers of rows where values change

b=diff(a);%a being your matrix c=find(b(:,1)~=0|b(:,2)~=0);%c=3,5,7

19 days ago | 1

Answered

how to create a random integernumbers with conditions?

A=[4 3 3]; a=[]; for k=1:length(A) a=[a,repmat(k,1,A(k))]; end for k=1:5 a=a(randperm(length(a)));%you don't neces...

how to create a random integernumbers with conditions?

A=[4 3 3]; a=[]; for k=1:length(A) a=[a,repmat(k,1,A(k))]; end for k=1:5 a=a(randperm(length(a)));%you don't neces...

20 days ago | 0

Answered

I have to find the sum of the elements in the upper dimension matrix and this is the code i came up with. When I submitted this code it's showing error.

Why not just: [a,b]=size(A); if a==b summa=sum(triu(A),'all'); end

I have to find the sum of the elements in the upper dimension matrix and this is the code i came up with. When I submitted this code it's showing error.

Why not just: [a,b]=size(A); if a==b summa=sum(triu(A),'all'); end

21 days ago | 0

Answered

create coordination matrix from zig zag path

x=0:9;%xend odd only y=[0;410;410;0]; A=[repelem(x',2),repmat(y,(x(end)+1)/2,1)];

create coordination matrix from zig zag path

x=0:9;%xend odd only y=[0;410;410;0]; A=[repelem(x',2),repmat(y,(x(end)+1)/2,1)];

21 days ago | 0

| accepted

Answered

How to represent a set of matrices into a single cell?

I would keep them all in a single matrix and then form matrix E (a*b X 4) where each row would hold the cell information of your...

How to represent a set of matrices into a single cell?

I would keep them all in a single matrix and then form matrix E (a*b X 4) where each row would hold the cell information of your...

22 days ago | 1

Answered

Calculating Harmonic Average in Matlab Function

What is ky? Why not just perform vectorized? No need to index into k. k can be any length vector and the below will calculate th...

Calculating Harmonic Average in Matlab Function

What is ky? Why not just perform vectorized? No need to index into k. k can be any length vector and the below will calculate th...

23 days ago | 0

Answered

How to calculate the jumper's final distance on this problem?

function dist=BJump(v,theta,rho,s) x=0; g=9.81; c=.72; dt=.000001;%not sure how accurate you need y=v*s...

How to calculate the jumper's final distance on this problem?

function dist=BJump(v,theta,rho,s) x=0; g=9.81; c=.72; dt=.000001;%not sure how accurate you need y=v*s...

24 days ago | 0

| accepted