working with an array
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a program that cuts out points from a two-dimensional vector that are at a distance 'd' from each other. The program starts working from the first element of the second column of the array. I want to add the value 'x0' to the value of this element and that the program starts with this value.
I have attached the vector to the message.
Thank you in advance.
This is my code:
format longG
d = 0.4053/sqrt(3); %0.4053
ii = 2;
a_0 = 0;
%a_0 = optimvar('a_0',43521); %!!!!!!!!!!!!!!!
general_t_d(:,1) = gn_nach(:,1);
general_t_d(:,2) = gn_nach(:,2);
general_t_d(:,2) = general_t_d(:,2) + a_0; % addition a_0
while ii < size(general_t_d,1)
if abs(general_t_d(ii+1,2) - general_t_d(ii,2)) < d
general_t_d(ii+1,:) = [];
else
ii = ii + 1;
end
end
3 Commenti
Risposte (1)
Vedant Shah
il 20 Giu 2025
The provided MATLAB code operates on a two-dimensional array, where the second column contains values that are iteratively compared to filter out rows based on a specified distance threshold, d.
To modify the behaviour such that the filtering process begins from a value offset by a small amount ‘x0’ from the first element in the second column, it is necessary to first define ‘x0’. Subsequently, all rows with second-column values less than this adjusted starting point should be removed prior to initiating the filtering logic.
Below is the revised version of the code that incorporates this functionality:
format longG
d = 0.4053/sqrt(3);
x0 = 0.00015;
a_0 = 0;
general_t_d = gn_nach;
general_t_d(:,2) = general_t_d(:,2) + a_0;
% Remove rows where B < B(1) + x0
start_value = general_t_d(1,2) + x0;
general_t_d = general_t_d(general_t_d(:,2) >= start_value, :);
ii = 1;
while ii < size(general_t_d,1)
if abs(general_t_d(ii+1,2) - general_t_d(ii,2)) < d
general_t_d(ii+1,:) = [];
else
ii = ii + 1;
end
end
This approach ensures that the filtering begins from the desired offset and that all preceding data points are excluded from the analysis.
For more information, refer to the following documentations:
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!