How to modify the code to compute data on multiple inputs?
Show older comments
Hi,
I have attached the snap of my code, I am computing data by using vp vs and rho each of size 116 * 227. The data should be computed as e.g., data1 from vp(:,1), vs(:,1) and rho(:,1) on three theta (15 30 45) and then in the next stage: data2 from vp(:,2), vs(:,2) and rho(:,2) on three theta (15 30 45) and so on... until 227.
How can I adjust my code to perform like this? It means I should have 227 set of output data each have three traces at three theta values (as theta are 15 30 45).

1 Comment
Jo
on 4 Feb 2024
Certainly! Here's a shorter version:
- Function Signature:Update the function signature to accept multiple inputs.python
- def your_function(*inputs):
# existing code
- Loop or Iterate:If inputs are iterable, loop through them.python
- def process_multiple_inputs(inputs):
for input_data in inputs:
# process input_data
- Parallel Processing:For parallel processing, consider using concurrent.futures.python
- from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor() as executor:
results = list(executor.map(process_function, inputs))
- Modularization:Break code into smaller functions for readability.python
- def process_input(input_data):
# process individual input
def process_multiple_inputs(inputs):
results = [process_input(data) for data in inputs]
Adjust the suggestions based on your specific code and requirements.
Accepted Answer
More Answers (1)
Next time please copy paste the code, not screen shot :D
You did not provide full info to get an answer since I have no idea how fwmod_vpvsrho function you have.
Having said that you can either modify your fwmod_vpvsrho function to allow an array inputs for theta variable or you can do:
for i = 1:length(theta)
data(:,:,i) = fwmod_vpvsrho(vp,vs,rho,theta(i),wav,t0,dt)
end
WIth this data(:,:,i) refers to the data at theta(i). so the data variable is a 116x227x3 matrix.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!