MatLab Matrix Help: Integrating for Entries Equal to 1

  • Context: MATLAB 
  • Thread starter Thread starter Apteronotus
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Click For Summary
SUMMARY

The discussion focuses on integrating matrix entries in MatLab where corresponding entries in matrix B equal 1. The user initially attempts to use the quad function, which is outdated and not recommended. Instead, the integral function should be utilized for this purpose. Additionally, the use of ARRAYFUN is suggested as a potential solution to avoid nested loops for large matrices.

PREREQUISITES
  • Understanding of MatLab matrix operations
  • Familiarity with numerical integration functions in MatLab
  • Knowledge of vectorization in MatLab
  • Basic programming skills in MatLab
NEXT STEPS
  • Learn how to use the MatLab integral function for numerical integration
  • Explore the ARRAYFUN function for applying operations to arrays
  • Study MatLab documentation on vectorization techniques
  • Investigate alternatives to quad for numerical integration in MatLab
USEFUL FOR

MatLab users, data analysts, and engineers looking to perform efficient numerical integrations on matrices without using outdated functions.

Apteronotus
Messages
201
Reaction score
0
Hi,

I have a quick question regarding MatLab.

I have 3 matracies A, B and C.

For every entry equal to 1 in B, I want to let the corresponding entry in A be an integral of x from 0 to C.

ex.
for all (i,j)
if B(i,j)==1 then let A(i,j)=quad(@(x) x, 0, C(i,j))

A quick way to do this for large matracies I thought was to use the following syntax:
A(B==1) = quad(@(x) x, 0, C(B==1))

But get the following error:
? Error using ==> quad at 70
The limits of integration must be scalars.

Is there any way around this other than a "for i, for j" statement?

Thanks,
 
Physics news on Phys.org

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K