Arranging Different Array Values according to X and Y Coordinates

8 次查看(过去 30 天)
I have four arrays that I need to deal with inside a for loop. Two of the arrays are storing the X and Y coordinates where the measurements are obtained, The other two are measurement related arrays. I need to use the X and Y arrays inside the for loop, so that the corresponding measurements (data in other two arrays) at specific coordinate points (i.e. x=500 and y=-200, x=500 and y=-400, etc.) are going to be averaged together and a curve will be fitted on top of it. There are multiple measurements taken at each coordinate point, so the code needs to understand how many data is recorded at each point, which is not going to be same at each point as well.
I need to understand by both checking the X and Y arrays simultaneously and understand when any one of the coordinate values is changed since it will correspond to a new data point. Through understanding this, with the number of measurements taken (understood by tracking the coordinate points after sorting the arrays) the data will be taken from other arrays in order to be processed.
I would appreciate any help if there is a solution to this issue.

回答(1 个)

Balavignesh
Balavignesh 2023-9-26
编辑:Balavignesh 2023-9-27
Hi Bugrahan,
As per my understanding, you would like to access two coordinate arrays and two measurement arrays inside a 'for' loop. I assume that there is a mechanism to record the number of measurements for each set of coordinate points.
I would suggest you to sort the coordinate arrays and pre-allocate the result arrays for faster computations.
You can use two 'for' loops to access the data in 'measurement' arrays and perform the necessary calculations. Then you can store the computed values in the result arrays, which can be used to plot in further steps.
Here is an example showing how you can do this:
% Initialising with some trash data. Input your own data
x = [1 2 3 4 5];
y = [1 2 3 4 5];
data1 = [10 1 2 3 5 4 11 2 3 45 90 123 64 87 95 90];
data2 = [10 2 3 4 32 1 32 4 5 6 32 34 2 342 34 56 54];
% Sort the x and y coordinates
data_initial_index = 1;
% Pre-allocating the required average arrays
avg_data_1 = zeros(length(x), length(y));
avg_data_2 = zeros(length(x), length(y));
for i = 1:length(x)
for j = 1:length(y)
k = number_measurements_recorded(x(i),y(j)); % function to record the number of measurements
% Do the necessary calculations
end
end
% Plot the desired data
function result = number_measurements_recorded(x,y)
result = 8;
end
Please refer to the following documentation for more information on:

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by