Answered

Population growth in 7 years

% rate r = 0.0063; % years t = 7; % initial population a = 5e6; % population y = a*(1+r)^t

Population growth in 7 years

% rate r = 0.0063; % years t = 7; % initial population a = 5e6; % population y = a*(1+r)^t

1 day ago | 1

| accepted

Answered

Apply operation to each element of an array

You should use element-wise operations https://it.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html In you...

Apply operation to each element of an array

You should use element-wise operations https://it.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html In you...

1 day ago | 0

| accepted

Answered

How do you solve for a double sum

There are some things that are vgue, like the x-axis, in any case, this code shows something similar to the desired result clea...

How do you solve for a double sum

There are some things that are vgue, like the x-axis, in any case, this code shows something similar to the desired result clea...

4 days ago | 1

| accepted

Answered

Solving System of Equations

It seems you are solving a numeric system of equations. Why don't you simply put the coefficient matrix in A and the right-hand-...

Solving System of Equations

It seems you are solving a numeric system of equations. Why don't you simply put the coefficient matrix in A and the right-hand-...

5 days ago | 0

Answered

Finding values within a matrix

It is difficult to answer because we don't have the data files 'areatemp1' and 'machtemp1'. In any case in your if statement yo...

Finding values within a matrix

It is difficult to answer because we don't have the data files 'areatemp1' and 'machtemp1'. In any case in your if statement yo...

5 days ago | 0

Answered

Making a 3D Matrix and Adding Matrices to make a bigger matrix

In the loop, you wrote T(i+k-1,j+k-1) = d(i,j,k-1); k starts from one, so you are trying to access the d(i,j,0) elemen...

Making a 3D Matrix and Adding Matrices to make a bigger matrix

In the loop, you wrote T(i+k-1,j+k-1) = d(i,j,k-1); k starts from one, so you are trying to access the d(i,j,0) elemen...

6 days ago | 0

Answered

Computational Electromagnetics and MATLAB

This could be a good start https://it.mathworks.com/academia/books/computational-electromagnetics-with-matlab-sadiku.html

Computational Electromagnetics and MATLAB

This could be a good start https://it.mathworks.com/academia/books/computational-electromagnetics-with-matlab-sadiku.html

6 days ago | 1

| accepted

Answered

Why am i getting the : errir using inv ,Matrix must be square?

As James Tursa said, inv(H) is not defined when H is not square. If you have the matrix H and the rhs g, simply use f = H\g;

Why am i getting the : errir using inv ,Matrix must be square?

As James Tursa said, inv(H) is not defined when H is not square. If you have the matrix H and the rhs g, simply use f = H\g;

7 days ago | 0

Answered

Struggling to Vectorize the following Code.

Almost all execution time is due to the plot function as highlighted by the profiler: You can call the plot only once at the ...

Struggling to Vectorize the following Code.

Almost all execution time is due to the plot function as highlighted by the profiler: You can call the plot only once at the ...

7 days ago | 0

Answered

How can I pick certain element from each row of an array ?

I see that the edges shared by two triangles are not duplicated. To check for this case I sorted the nodes and the edges. Let me...

How can I pick certain element from each row of an array ?

I see that the edges shared by two triangles are not duplicated. To check for this case I sorted the nodes and the edges. Let me...

7 days ago | 0

| accepted

Answered

Combining my newton's method function for nonlinear equations and my lu decomposition function.

Is this what you are asking for? delta = LUgauss(J(x0),-F_value); Note that the buil-in lu Matlab function can do the work for...

Combining my newton's method function for nonlinear equations and my lu decomposition function.

Is this what you are asking for? delta = LUgauss(J(x0),-F_value); Note that the buil-in lu Matlab function can do the work for...

8 days ago | 0

Answered

How to sum over rows within specific ranges without for loop?

Not sure if it is the best way, but this seems to work index = [0; cumsum(B)]; C = cell2mat(arrayfun(@(i)sum(A(index(i)+1:in...

How to sum over rows within specific ranges without for loop?

Not sure if it is the best way, but this seems to work index = [0; cumsum(B)]; C = cell2mat(arrayfun(@(i)sum(A(index(i)+1:in...

8 days ago | 0

| accepted

Answered

Removing Outbound (out of range) data from an array

% dimension N = 1000000; % data in (0,1) x = rand(N,1); % threshold xMin = 0.25; xMax = 0.75; % remove data out of ...

Removing Outbound (out of range) data from an array

% dimension N = 1000000; % data in (0,1) x = rand(N,1); % threshold xMin = 0.25; xMax = 0.75; % remove data out of ...

10 days ago | 0

| accepted

Answered

How to select specific values and corresponding cell positions from 31 x 12 matrix?

Because the number of rows in B is not fixed, you can store the result of your check in a cell array % create the matrix A = (...

How to select specific values and corresponding cell positions from 31 x 12 matrix?

Because the number of rows in B is not fixed, you can store the result of your check in a cell array % create the matrix A = (...

10 days ago | 0

Answered

I have a problem with integration "Error using / Matrix dimensions must agree"

When you define your functions use ./ instead of / %function f=(x+(1./x)).^2; %real value of integral ff=@(x)(x+(1./x)).^2;

I have a problem with integration "Error using / Matrix dimensions must agree"

When you define your functions use ./ instead of / %function f=(x+(1./x)).^2; %real value of integral ff=@(x)(x+(1./x)).^2;

10 days ago | 1

| accepted

Answered

Cause of: "Error: Inputs must be floats, namely single or double."

What I can see is 1) Fs is missing. In any case, tspan shpuld be a 2 entries array with initial and final values tspan = [0,15...

Cause of: "Error: Inputs must be floats, namely single or double."

What I can see is 1) Fs is missing. In any case, tspan shpuld be a 2 entries array with initial and final values tspan = [0,15...

13 days ago | 1

Answered

how to convert cell to matrix ?

A = cell2mat(cellfun(@str2num,x,'UniformOutput',false))

how to convert cell to matrix ?

A = cell2mat(cellfun(@str2num,x,'UniformOutput',false))

15 days ago | 1

Answered

Possible to modify only one portion of an array in one line?

x(x > xMax & 1:length(x) > transition) = xMax

Possible to modify only one portion of an array in one line?

x(x > xMax & 1:length(x) > transition) = xMax

15 days ago | 2

| accepted

Answered

How to compare the closest value in the matrix?

% your data unknownM = [0.8105 1.1581 0.6295 0.9594 0.8447 0.7103 0.8429 0.5372 0.9882 0.8924]; sud...

How to compare the closest value in the matrix?

% your data unknownM = [0.8105 1.1581 0.6295 0.9594 0.8447 0.7103 0.8429 0.5372 0.9882 0.8924]; sud...

16 days ago | 0

Answered

how can I create a 4D matrix and use it for interpolation

% your vectors Wpig=0.5:0.5:7; Chla=0.5:0.01:0.6; Starch=0:0.04:0.24; Now you need to sample uniformly the space using your...

how can I create a 4D matrix and use it for interpolation

% your vectors Wpig=0.5:0.5:7; Chla=0.5:0.01:0.6; Starch=0:0.04:0.24; Now you need to sample uniformly the space using your...

18 days ago | 0

Answered

How can i break down the values of vector into group of five?

If x is your vector you can reshape it y = reshape(x,5,numel(x)/5); and access each column with indexing % column 10 iCol = ...

How can i break down the values of vector into group of five?

If x is your vector you can reshape it y = reshape(x,5,numel(x)/5); and access each column with indexing % column 10 iCol = ...

18 days ago | 0

Answered

index in position 2 exceeds array bounds ( must not exceed 1).

Difficult to say without file, code, etc. The wizard says that the new excel file has only one column, but the code expects tw...

index in position 2 exceeds array bounds ( must not exceed 1).

Difficult to say without file, code, etc. The wizard says that the new excel file has only one column, but the code expects tw...

18 days ago | 0

Answered

if statement in for loop with cell arrays

To stick with the OP snippet I added semicolons all over the place I changed the variable type in s.score to doubles I preall...

if statement in for loop with cell arrays

To stick with the OP snippet I added semicolons all over the place I changed the variable type in s.score to doubles I preall...

18 days ago | 0

Answered

How to create an array and fill it by these values using loop ?

% intialization and preallocation k = 1; date = strings(480,1); % string array for i = 1982:2015 for j = 1:12 ...

How to create an array and fill it by these values using loop ?

% intialization and preallocation k = 1; date = strings(480,1); % string array for i = 1982:2015 for j = 1:12 ...

18 days ago | 0

| accepted

Answered

Monte Carlo integration of sin(x)

This code evaluates the integral using the Monte Carlo method with increasing number of random samples, compare the result with ...

Monte Carlo integration of sin(x)

This code evaluates the integral using the Monte Carlo method with increasing number of random samples, compare the result with ...

18 days ago | 0

Answered

Check if a number is in between two values

% your data a = [1,2,3,4,5,6]' b = [10,11,12,13,14,15]' Interval = [a b]; % number to check x = 8; % this finds the in...

Check if a number is in between two values

% your data a = [1,2,3,4,5,6]' b = [10,11,12,13,14,15]' Interval = [a b]; % number to check x = 8; % this finds the in...

18 days ago | 0

Answered

Assembling Element Matrices in Finite Element Method Problem

If I have understood correctly, you want to store the local 3x3 matrix in the global matrix. To do so you can (I would say must)...

Assembling Element Matrices in Finite Element Method Problem

If I have understood correctly, you want to store the local 3x3 matrix in the global matrix. To do so you can (I would say must)...

19 days ago | 1

Answered

How to find corresponding row positions of specific values in a matrix?

The function min will do this for you [B,C] = min(A,[],1);

How to find corresponding row positions of specific values in a matrix?

The function min will do this for you [B,C] = min(A,[],1);

20 days ago | 0

| accepted

Answered

How to convert script from fortran90 to matlab language

Again, it is difficult to check if not all code is available, however I try kB = zeros(10,1); kA = zeros(10,1); kL = 0; kS =...

How to convert script from fortran90 to matlab language

Again, it is difficult to check if not all code is available, however I try kB = zeros(10,1); kA = zeros(10,1); kL = 0; kS =...

20 days ago | 1

| accepted

Answered

Pad with Nan according to maximum row in cell

I keep all steps separated % the data A = {rand(47,1),rand(80,1),rand(97,1)}; % pad with NaNs A = cellfun(@(x)[x(1:end); N...

Pad with Nan according to maximum row in cell

I keep all steps separated % the data A = {rand(47,1),rand(80,1),rand(97,1)}; % pad with NaNs A = cellfun(@(x)[x(1:end); N...

20 days ago | 0

| accepted