MatLab Matrix Help: Integrating for Entries Equal to 1

  • Context: MATLAB 
  • Thread starter Thread starter Apteronotus
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
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