The data points are attached here.
Mapping 1D vector to 2D area
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Prasanna Routray
am 27 Sep. 2024
Kommentiert: Prasanna Routray
am 2 Nov. 2024
load xPoints; load yPoints; j=boundary(xPoints,yPoints,0.1); Plot(xPoints(j),yPoints(j))
![](/matlabcentral/answers/uploaded_files/1780075/IMG-20240927-WA0011.jpg)
%How do I map the x-values to y-values here?
4 Kommentare
Image Analyst
am 27 Sep. 2024
What if, for a given vertical line (like you specified x with some specific value), there are no y values for that exact x value? Maybe some are close but not exact. Do you want to find all y values within a certain tolerance of your specified x? If so use ismembertol().
Akzeptierte Antwort
Cris LaPierre
am 27 Sep. 2024
Are you wanting all the corresponding yPoints, or just those on the boundary?
load xPoints;
load yPoints;
j=boundary(xPoints,yPoints,0.1);
To me, the simplest approach is to find the indices of the desired X value, and use that the extract the corresponding Y values.
idx = xPoints==2;
yPoints(idx)
That will return all points. If you just want them from the boundary, try this.
ids = xPoints(j)==2;
yPoints(j(ids))
Here, only one value is returned because only one X value in boundary exactly equals 2. In that case, you could use ismembertol.
LIA = ismembertol(xPoints(j),2,0.01);
yPoints(j(LIA))
9 Kommentare
Cris LaPierre
am 1 Nov. 2024
Bearbeitet: Cris LaPierre
am 1 Nov. 2024
The difference approach doesn't appear to be working here. Assuming the boundary shape is always like this, consider using the location of the max x value to separate your data.
load xPointsNew;
load yPointsNew;
j=boundary(xPointsNew,yPointsNew,0.1);
plot(xPointsNew(j),yPointsNew(j))
[~,ind] = max(xPointsNew(j))
% Define x value
x = 5;
% Can only use interp on unique X values, so split j into increasing and
% decreasing x values
idx1 = 1:ind-1;
idx2 = ind:length(j);
% interpolate to find corresponding y values when increasing and decreasing
y1 = interp1(xPointsNew(j(idx1)),yPointsNew(j(idx1)),x);
y2 = interp1(xPointsNew(j(idx2)),yPointsNew(j(idx2)),x);
y = [y1,y2]
hold on
plot(x*ones(length(y),1),y)
hold off
Weitere Antworten (1)
Rahul
am 27 Sep. 2024
I believe that you're trying to want to obtain a reverse mapping, from xPoints data to yPoints data, using a MATLAB function. Here's how you can code the same:
function [res_x, res_y] = getYs(x, xPoints, yPoints)
x = 5;
n = size(xPoints, 1);
res_y = [];
res_x = [];
for i=1:n
if xPoints(i) == x
res_y = [res_y yPoints(i)];
res_x = [res_x x];
end
end
end
Use the above function to get yPoints values corresponding to a given 'x', plot the resultant values on the figure, and display the resultant array 'res_y':
load xPoints; load yPoints;
j=boundary(xPoints,yPoints,0.1);
plot(xPoints(j),yPoints(j), 'Color','black');
hold on;
% Call getYs to get corresponding y values for a given x = 5
x = 5;
[res_x, res_y] = getYs(x, xPoints, yPoints);
% Plot returned data using dotted red line on same graph
plot(res_x, res_y, 'r.');
disp(res_y);
hold off;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1780215/image.png)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!